Skip to content

Print better compiler error for duplicate identifiers #793

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

Closed
MaxGraey opened this issue Aug 26, 2019 · 4 comments
Closed

Print better compiler error for duplicate identifiers #793

MaxGraey opened this issue Aug 26, 2019 · 4 comments

Comments

@MaxGraey
Copy link
Member

MaxGraey commented Aug 26, 2019

class Foo {
  field: i32;
  field: i64;
}
const foo = new Foo();

But this should be valid:

class Foo {
  field: i32;
  static field: i64;
}

Expected compiler error:

Dublicate identifier 'field'

Actual:

ERROR: AssertionError: assertion failed
@DanielRX
Copy link

Me and @karzanbotani are currently working this fix now, is there a set way you want it to error?

This is the current message we have:

ERROR: AssertionError: Duplicate instance member: 'field' in file 'test.ts', line: 3 column: 15
    at assert (*/assemblyscript/std/portable/index.js:184:9)
    at Compiler.compileTopLevelStatement (*/assemblyscript/src/compiler.ts:1635:11)
    at Compiler.compileFile (*/assemblyscript/src/compiler.ts:759:12)
    at Compiler.compile (*/assemblyscript/src/compiler.ts:366:14)
    at Object.compileProgram (*/assemblyscript/src/index.ts:146:41)
    at stats.compileTime.measure (*/assemblyscript/cli/asc.js:591:31)
    at measure (*/assemblyscript/cli/asc.js:929:3)
    at Object.main (*/assemblyscript/cli/asc.js:590:26)
    at Object.<anonymous> (*/assemblyscript/bin/asc:21:26)
    at Module._compile (internal/modules/cjs/loader.js:688:30)

@MaxGraey
Copy link
Member Author

MaxGraey commented Aug 26, 2019

@DanielRX Great! But instead of AssertionError I guess it should be diagnostic error in ASxxx space similar to "Duplicate decorator" error here

EDIT
Actualy we already have this error. But if you create another one with "Duplicate instance member '{0}' in file '{1}'": 2301 this will be even better

@DanielRX
Copy link

Noted, as a side point, we are going to add static and instance errors, so that it covers both cases.

@MaxGraey MaxGraey changed the title Print better compiler error for dublicate identifiers Print better compiler error for duplicate identifiers Aug 26, 2019
@dcodeIO
Copy link
Member

dcodeIO commented Dec 5, 2019

This is emitting a diagnostic with a related range now, indicating both the initial declaration and the duplicate one.

@dcodeIO dcodeIO closed this as completed Dec 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants