diff --git a/src/types/__snapshots__/resolveStatements.spec.ts.snap b/src/types/__snapshots__/resolveStatements.spec.ts.snap index 3c3ecfe82..31c0595aa 100644 --- a/src/types/__snapshots__/resolveStatements.spec.ts.snap +++ b/src/types/__snapshots__/resolveStatements.spec.ts.snap @@ -250,6 +250,16 @@ Line 23, col 18: " `; +exports[`resolveStatements should fail statements for case-25 1`] = ` +":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`] = ` [ [ diff --git a/src/types/resolveExpression.ts b/src/types/resolveExpression.ts index d26f9281c..c4570874a 100644 --- a/src/types/resolveExpression.ts +++ b/src/types/resolveExpression.ts @@ -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') { diff --git a/src/types/stmts-failed/case-25.tact b/src/types/stmts-failed/case-25.tact new file mode 100644 index 000000000..c77d25c2d --- /dev/null +++ b/src/types/stmts-failed/case-25.tact @@ -0,0 +1,6 @@ +primitive Int; +primitive Bool; + +fun foo(x: Int): Bool { + return x == true; +}