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

feat: include expected type for invalid type error message #1738

Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions dev-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Better error message for `extend function without parameters` error: PR [#1624](https://github.com/tact-lang/tact/pull/1624)
- Don't generate `lazy_deployment_completed` by default: PR [#1717](https://github.com/tact-lang/tact/pull/1717)
- Optimized `emptyCell()` and `emptySlice()` functions: PR [#1696](https://github.com/tact-lang/tact/pull/1696)
- Error message for invalid type for function argument now shows expected type: PR [#1738](https://github.com/tact-lang/tact/pull/1738)

### Fixed

Expand Down
6 changes: 3 additions & 3 deletions src/types/__snapshots__/resolveStatements.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ exports[`resolveStatements should fail statements for contract-getter-with-metho
`;

exports[`resolveStatements should fail statements for contract-initof-wrong-arg 1`] = `
"<unknown>:26:25: Invalid type "String" for argument "owner"
"<unknown>:26:25: Cannot pass a value of type "String" to the parameter "owner" of type "Int"
25 | get fun newInit(): StateInit {
> 26 | return initOf A("hello");
^~~~~~~
Expand Down Expand Up @@ -385,7 +385,7 @@ exports[`resolveStatements should fail statements for expr-field-does-not-exist-
`;

exports[`resolveStatements should fail statements for expr-internal-fun-call-bool-param.tact 1`] = `
"<unknown>:20:27: Invalid type "Bool" for argument "b"
"<unknown>:20:27: Cannot pass a value of type "Bool" to the parameter "b" of type "Int"
19 | fun f2(a: Int): Int {
> 20 | return self.f1(a, true);
^~~~
Expand Down Expand Up @@ -448,7 +448,7 @@ exports[`resolveStatements should fail statements for expr-method-does-not-exist
`;

exports[`resolveStatements should fail statements for expr-module-fun-call-bool-param 1`] = `
"<unknown>:13:18: Invalid type "Bool" for argument "b"
"<unknown>:13:18: Cannot pass a value of type "Bool" to the parameter "b" of type "Int"
12 | fun f2(a: Int): Int {
> 13 | return f1(a, true);
^~~~
Expand Down
6 changes: 3 additions & 3 deletions src/types/resolveExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ function resolveStaticCall(
const t = getExpType(ctx, e);
if (!isAssignable(t, a.type)) {
throwCompilationError(
`Invalid type "${printTypeRef(t)}" for argument ${idTextErr(a.name)}`,
`Cannot pass a value of type "${printTypeRef(t)}" to the parameter ${idTextErr(a.name)} of type "${printTypeRef(a.type)}"`,
e.loc,
);
}
Expand Down Expand Up @@ -658,7 +658,7 @@ function resolveCall(
const t = getExpType(ctx, e);
if (!isAssignable(t, a.type)) {
throwCompilationError(
`Invalid type "${printTypeRef(t)}" for argument ${idTextErr(a.name)}`,
`Cannot pass a value of type "${printTypeRef(t)}" to the parameter ${idTextErr(a.name)} of type "${printTypeRef(a.type)}"`,
e.loc,
);
}
Expand Down Expand Up @@ -783,7 +783,7 @@ function resolveInitOf(
const t = getExpType(ctx, e);
if (!isAssignable(t, a.type)) {
throwCompilationError(
`Invalid type "${printTypeRef(t)}" for argument ${idTextErr(a.name)}`,
`Cannot pass a value of type "${printTypeRef(t)}" to the parameter ${idTextErr(a.name)} of type "${printTypeRef(a.type)}"`,
e.loc,
);
}
Expand Down