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

fix: support T and T? methods with the same name #1758

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

i582
Copy link
Contributor

@i582 i582 commented Feb 10, 2025

Issue

Closes #1285.

Checklist

  • I have updated CHANGELOG.md
  • I have added tests to demonstrate the contribution is correctly implemented: this usually includes both positive and negative tests, showing the happy path(s) and featuring intentionally broken cases
  • I have run all the tests locally and no test failure was reported
  • I have run the linter, formatter and spellchecker
  • I did not do unrelated and/or undiscussed refactorings

@i582 i582 changed the title fix: clash of methods for non-optional and optional types fix: support T and T? methods with the same name Feb 10, 2025
@i582 i582 marked this pull request as ready for review February 10, 2025 11:00
@i582 i582 requested a review from a team as a code owner February 10, 2025 11:00
@novusnota novusnota added this to the v1.6.0 milestone Feb 11, 2025
@anton-trunov anton-trunov self-assigned this Feb 13, 2025
@@ -353,7 +353,7 @@ export const MapFunctions: ReadonlyMap<string, AbiFunction> = new Map([
const [self] = args;
checkMapType(self, ref);

return { kind: "ref", name: "Cell", optional: true };
return { kind: "ref", name: "Cell", optional: false };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, this wouldn't fail at runtime?

contract Foo {
    get fun foo(): Slice {
        let x: map<Int, Int> = emptyMap();
        return x.asCell().asSlice();
    }
}

Copy link
Member

@Gusarich Gusarich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The snippet below throws an internal compiler error.

extends fun foo(self: Int) {
    return self * 2;
}

fun bar(x: Int?) {
    x.foo();
}
[INTERNAL COMPILER ERROR]: Type Int_optional not found
    Please report at https://github.com/tact-lang/tact/issues

       96 |     const msg = `[INTERNAL COMPILER ERROR]: ${message}\nPlease report at https://github.com/tact-lang/tact/issues`;
       97 |     throw source === undefined
    >  98 |         ? new TactInternalCompilerError(msg)
          |           ^
       99 |         : new TactInternalCompilerError(
      100 |               `${locationStr(source)}\n${msg}\n${source.interval.getLineAndColumnMessage()}`,
      101 |               source,

      at throwInternalCompilerError (src/error/errors.ts:98:11)
      at getType (src/types/resolveDescriptors.ts:2113:35)
      at resolveCall (src/types/resolveExpression.ts:644:29)
      at resolveExpression (src/types/resolveExpression.ts:947:20)
      at processStatements (src/types/resolveStatements.ts:434:48)
      at processFunctionBody (src/types/resolveStatements.ts:763:17)
      at resolveStatements (src/types/resolveStatements.ts:803:19)
      at Object.<anonymous> (src/types/resolveStatements.spec.ts:24:36)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Methods for non-optional and optional types clash
4 participants