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

Added helpful error when missing type parameters #1182

Merged
merged 2 commits into from
Mar 24, 2020

Conversation

DuncanUszkay1
Copy link
Contributor

Issue: #1181

When we were resolving a function from an identifier, we would call the resolveFunction method without any typeArguments. This guarantees an assertion failure in the event that the function requires type parameters.

This PR adds a check in the compileIdentifierExpression call just before it tries to resolve the function which will print out a nicer error message.

function doit<T,X,O,N>(x: T): T {
  return x
}
export function test(x: i32): void {
  let x = doit<String("hey!");
}

Before:

Results in:

ERROR: AssertionError: assertion failed

After

Results in:

ERROR TS2554: Expected 4 arguments, but got 0.

   let x = doit<String("hey!");
           ~~~~
 in main.ts(9,11)

ERROR AS225: Expression cannot be represented by a type.

   let x = doit<String("hey!");
                ~~~~~~~~~~~~~~
 in main.ts(9,16)

src/compiler.ts Outdated Show resolved Hide resolved
@DuncanUszkay1 DuncanUszkay1 force-pushed the fix-angle-bracket-assert branch from 45b3bf4 to a5f9eb4 Compare March 24, 2020 00:39
src/compiler.ts Outdated Show resolved Hide resolved
Co-Authored-By: Max Graey <maxgraey@gmail.com>
@dcodeIO dcodeIO merged commit 0553d16 into AssemblyScript:master Mar 24, 2020
@dcodeIO
Copy link
Member

dcodeIO commented Mar 24, 2020

Thanks!

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.

4 participants