Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling methods on null when self is of an optional type is not allowed #1283

Open
anton-trunov opened this issue Jan 4, 2025 · 2 comments
Assignees
Labels
bug Something isn't working or isn't right typechecker
Milestone

Comments

@anton-trunov
Copy link
Member

null.foo() should be allowed in the snippet below:

extends fun foo(self: Int?): Bool {
    if (self == null) { return false }
    else { return self!! == 42 }
}

contract Test {
    get fun test(): Bool {
        return null.foo();
    }
}

Now I get the following compilation error message:

Tact compilation failed
Error: test-null.tact:8:16: Invalid type "<null>" for function call
Line 8, col 16:
  7 |     get fun test(): Bool {
> 8 |         return null.foo();
                     ^~~~~~~~~~
  9 |     }
@anton-trunov anton-trunov added bug Something isn't working or isn't right typechecker labels Jan 4, 2025
@anton-trunov anton-trunov added this to the v1.6.0 milestone Jan 4, 2025
@Gusarich Gusarich self-assigned this Jan 9, 2025
@Gusarich
Copy link
Member

Gusarich commented Jan 9, 2025

@anton-trunov suppose there are two functions: foo(self: Int?) and foo(self: Bool?) and you try to call null.foo(). How should compiler decide which one of these to call?

@anton-trunov
Copy link
Member Author

@Gusarich In these cases you would need to use type annotations to disambiguate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working or isn't right typechecker
Projects
None yet
Development

No branches or pull requests

2 participants