Skip to content

Added helpful error when missing type parameters#1182

Merged
dcodeIO merged 2 commits into
AssemblyScript:masterfrom
DuncanUszkay1:fix-angle-bracket-assert
Mar 24, 2020
Merged

Added helpful error when missing type parameters#1182
dcodeIO merged 2 commits into
AssemblyScript:masterfrom
DuncanUszkay1:fix-angle-bracket-assert

Conversation

@DuncanUszkay1

Copy link
Copy Markdown
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)

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

dcodeIO commented Mar 24, 2020

Copy link
Copy Markdown
Member

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