diff --git a/NOTICE b/NOTICE index f9e5e9e9a2..672aca7358 100644 --- a/NOTICE +++ b/NOTICE @@ -15,6 +15,8 @@ under the licensing terms detailed in LICENSE: * Aaron Turner * Willem Wyndham * Bowen Wang +* Daniel Reed +* Karzan Botani Portions of this software are derived from third-party works licensed under the following terms: diff --git a/src/compiler.ts b/src/compiler.ts index 7c49599078..7e9799dc61 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -1651,6 +1651,7 @@ export class Compiler extends DiagnosticEmitter { break; } case NodeKind.FIELDDECLARATION: { + if (!this.program.elementsByDeclaration.has(statement)) { break; } let element = this.program.getElementByDeclaration(statement); if (element.kind == ElementKind.GLOBAL) { // static if (!element.hasDecorator(DecoratorFlags.LAZY)) this.compileGlobal(element); diff --git a/src/diagnosticMessages.generated.ts b/src/diagnosticMessages.generated.ts index 5e6f076bbe..9c2e8b6787 100644 --- a/src/diagnosticMessages.generated.ts +++ b/src/diagnosticMessages.generated.ts @@ -36,6 +36,8 @@ export enum DiagnosticCode { _0_must_be_a_power_of_two = 223, Expression_is_unsafe = 224, Expression_is_never_null = 225, + Duplicate_instance_member_0 = 231, + Duplicate_static_member_0 = 232, Unterminated_string_literal = 1002, Identifier_expected = 1003, _0_expected = 1005, @@ -176,6 +178,8 @@ export function diagnosticCodeToString(code: DiagnosticCode): string { case 223: return "'{0}' must be a power of two."; case 224: return "Expression is unsafe."; case 225: return "Expression is never 'null'."; + case 231: return "Duplicate instance member '{0}'."; + case 232: return "Duplicate static member '{0}'."; case 1002: return "Unterminated string literal."; case 1003: return "Identifier expected."; case 1005: return "'{0}' expected."; diff --git a/src/diagnosticMessages.json b/src/diagnosticMessages.json index 17c832cee4..e63d6c8361 100644 --- a/src/diagnosticMessages.json +++ b/src/diagnosticMessages.json @@ -28,6 +28,8 @@ "'{0}' must be a power of two.": 223, "Expression is unsafe.": 224, "Expression is never 'null'.": 225, + "Duplicate instance member '{0}'.": 231, + "Duplicate static member '{0}'.": 232, "Unterminated string literal.": 1002, "Identifier expected.": 1003, diff --git a/src/program.ts b/src/program.ts index d71a1dc445..e6d24b7bb1 100644 --- a/src/program.ts +++ b/src/program.ts @@ -2038,10 +2038,17 @@ export abstract class Element { if (merged) { element = merged; // use merged element } else { - this.program.error( - DiagnosticCode.Duplicate_identifier_0, - element.identifierNode.range, element.identifierNode.text - ); + if (element.is(CommonFlags.STATIC)) { + this.program.error( + DiagnosticCode.Duplicate_static_member_0, + element.identifierNode.range, element.identifierNode.text + ); + } else { + this.program.error( + DiagnosticCode.Duplicate_identifier_0, + element.identifierNode.range, element.identifierNode.text + ); + } return false; } } @@ -3040,7 +3047,7 @@ export class ClassPrototype extends DeclaredElement { let merged = tryMerge(instanceMembers.get(name)!, element); if (!merged) { this.program.error( - DiagnosticCode.Duplicate_identifier_0, + DiagnosticCode.Duplicate_instance_member_0, element.identifierNode.range, element.identifierNode.text ); return false; diff --git a/tests/compiler/class-duplicate.json b/tests/compiler/class-duplicate.json new file mode 100644 index 0000000000..1fd040b63f --- /dev/null +++ b/tests/compiler/class-duplicate.json @@ -0,0 +1,10 @@ +{ + "asc_flags": [ + "--runtime none" + ], + "stderr": [ + "AS231: Duplicate instance member 'field'.", + "AS232: Duplicate static member 'static_field'.", + "EOF" + ] +} \ No newline at end of file diff --git a/tests/compiler/class-duplicate.ts b/tests/compiler/class-duplicate.ts new file mode 100644 index 0000000000..1b2e97fb52 --- /dev/null +++ b/tests/compiler/class-duplicate.ts @@ -0,0 +1,13 @@ +// ERROR("SOF"); + +class FailureTest { + field: i64; + field: u32; + + static static_field: string; + static static_field: i32; +} + +const fail = new FailureTest(); + +ERROR("EOF"); \ No newline at end of file