Skip to content

Commit

Permalink
fix[typechecker]: catch diff types for == and != operators (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-trunov authored Feb 12, 2024
1 parent 619a143 commit c1da557
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
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;
}

0 comments on commit c1da557

Please sign in to comment.