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: typechecker did not catch diff types for == and != operators #127

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/types/__snapshots__/resolveStatements.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,16 @@ Line 23, col 18:
"
`;

exports[`resolveStatements should fail statements for case-25 1`] = `
"<unknown>:5:12: Incompatible types "Int" and "Bool" for binary operator "=="
Line 5, col 12:
4 | fun foo(x: Int): Bool {
> 5 | return x == true;
^~~~~~~~~
6 | }
"
`;

exports[`resolveStatements should resolve statements for case-0 1`] = `
[
[
Expand Down
2 changes: 1 addition & 1 deletion src/types/resolveExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function resolveBinaryOp(exp: ASTOpBinary, sctx: StatementContext, ctx: Compiler
if (l.kind !== 'ref' || r.kind !== 'ref') {
throwError(`Incompatible types "${printTypeRef(le)}" and "${printTypeRef(re)}" for binary operator "${exp.op}"`, exp.ref);
}
if (r.name !== r.name) {
if (l.name !== r.name) {
throwError(`Incompatible types "${printTypeRef(le)}" and "${printTypeRef(re)}" for binary operator "${exp.op}"`, exp.ref);
}
if (r.name !== 'Int' && r.name !== 'Bool' && r.name !== 'Address' && r.name !== 'Cell') {
Expand Down
6 changes: 6 additions & 0 deletions src/types/stmts-failed/case-25.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
primitive Int;
primitive Bool;

fun foo(x: Int): Bool {
return x == true;
}
Loading