Skip to content

Commit

Permalink
Report errors from initialize
Browse files Browse the repository at this point in the history
This is unfortunately necessary for the next commit. This is overall bad
for DX, since fewer errors are shown to the user at once.
  • Loading branch information
CountBleck committed Nov 21, 2023
1 parent d142ac8 commit 89b49f0
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 43 deletions.
8 changes: 7 additions & 1 deletion cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,12 @@ export async function main(argv, options) {
}
stats.initializeTime += stats.end(begin);
}
let numErrors = checkDiagnostics(program, stderr, opts.disableWarning, options.reportDiagnostic, stderrColors.enabled);
if (numErrors) {
const err = Error(`${numErrors} initialize error(s)`);
err.stack = err.message; // omit stack
return prepareResult(err);
}

// Call afterInitialize transform hook
{
Expand All @@ -740,7 +746,7 @@ export async function main(argv, options) {
? assemblyscript.getBinaryenModuleRef(module)
: module.ref
);
let numErrors = checkDiagnostics(program, stderr, opts.disableWarning, options.reportDiagnostic, stderrColors.enabled);
numErrors = checkDiagnostics(program, stderr, opts.disableWarning, options.reportDiagnostic, stderrColors.enabled);
if (numErrors) {
const err = Error(`${numErrors} compile error(s)`);
err.stack = err.message; // omit stack
Expand Down
7 changes: 7 additions & 0 deletions tests/compiler/covariance.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"stderr": [
"TS2394: This overload signature is not compatible with its implementation signature.",
"sibling: Cat | null;",
"sibling: Animal | null;"
]
}
9 changes: 9 additions & 0 deletions tests/compiler/covariance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Animal {
sibling: Animal | null;
}

class Cat extends Animal {
sibling: Cat | null; // covariance is unsound
}

new Cat();
10 changes: 2 additions & 8 deletions tests/compiler/duplicate-field-errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
],
"stderr": [
"TS2385: Overload signatures must all be public, private or protected.", "public privPub: i32;", "private privPub: i32;",
"TS2442: Types have separate declarations of a private property 'privPriv'.",
"TS2325: Property 'privProt' is private in type 'duplicate-field-errors/A' but not in type 'duplicate-field-errors/B'.",
"TS2325: Property 'privPub' is private in type 'duplicate-field-errors/A' but not in type 'duplicate-field-errors/B'.",
"TS2325: Property 'protPriv' is private in type 'duplicate-field-errors/B' but not in type 'duplicate-field-errors/A'.",
"TS2325: Property 'pubPriv' is private in type 'duplicate-field-errors/B' but not in type 'duplicate-field-errors/A'.",
"TS2444: Property 'pubProt' is protected in type 'duplicate-field-errors/B' but public in type 'duplicate-field-errors/A'.",
"TS2394: This overload signature is not compatible with its implementation signature.", "public method: i32;", "method(): void",
"TS2394: This overload signature is not compatible with its implementation signature.", "sibling: Cat | null;", "sibling: Animal | null;"
"TS2385: Overload signatures must all be public, private or protected.", "protected pubProt: i32;", "public pubProt: i32;",
"TS2416: Property 'method' in type 'duplicate-field-errors/B' is not assignable to the same property in base type 'duplicate-field-errors/A'."
]
}
8 changes: 0 additions & 8 deletions tests/compiler/duplicate-field-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,7 @@ class B extends A {
public method: i32;
}

class Animal {
sibling: Animal | null;
}
class Cat extends Animal {
sibling: Cat | null; // covariance is unsound
}

export function test(): void {
new A();
new B();
new Cat();
}
7 changes: 7 additions & 0 deletions tests/compiler/duplicate-identifier-function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"stderr": [
"TS2300: Duplicate identifier 'e'", "var e: f32", "var e: i32",
"TS2300: Duplicate identifier 'f'", "let f: f32",
"EOF"
]
}
12 changes: 12 additions & 0 deletions tests/compiler/duplicate-identifier-function.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function baz(): void {
var e: i32;
var e: f32;
{
let f: i32;
let f: f32;
}
}

baz();

ERROR("EOF"); // mark end and ensure fail
5 changes: 1 addition & 4 deletions tests/compiler/duplicate-identifier.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
"TS2300: Duplicate identifier 'a'", "var a: f32", "var a: i32",
"TS2300: Duplicate identifier 'b'", "b: f32", "b: i32",
"TS2300: Duplicate identifier 'c'", "static c: f32", " static c: i32",
"TS2300: Duplicate identifier 'd'", "const d: f32", "const d: i32",
"TS2300: Duplicate identifier 'e'", "var e: f32", "var e: i32",
"TS2300: Duplicate identifier 'f'", "let f: f32",
"EOF"
"TS2300: Duplicate identifier 'd'", "const d: f32", "const d: i32"
]
}
13 changes: 0 additions & 13 deletions tests/compiler/duplicate-identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,3 @@ namespace Bar {
const d: i32 = 0;
const d: f32 = 1;
}

function baz(): void {
var e: i32;
var e: f32;
{
let f: i32;
let f: f32;
}
}

baz();

ERROR("EOF"); // mark end and ensure fail
3 changes: 1 addition & 2 deletions tests/compiler/unmanaged-errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
],
"stderr": [
"AS207: Unmanaged classes cannot extend managed classes and vice-versa.", "UnmanagedFoo extends ManagedBase",
"AS207: Unmanaged classes cannot extend managed classes and vice-versa.", "ManagedFoo extends UnmanagedBase",
"EOF"
"AS207: Unmanaged classes cannot extend managed classes and vice-versa.", "ManagedFoo extends UnmanagedBase"
]
}
2 changes: 0 additions & 2 deletions tests/compiler/unmanaged-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ class ManagedBaz {}
class ManagedFoo extends UnmanagedBase { // AS207
constructor(public baz: ManagedBaz) { super(); }
}

ERROR("EOF");
5 changes: 5 additions & 0 deletions tests/compiler/unsafe-not-valid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": [
"AS212: Decorator '@unsafe' is not valid here."
]
}
3 changes: 3 additions & 0 deletions tests/compiler/unsafe-not-valid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Global

@unsafe var g = 0; // not valid here
1 change: 0 additions & 1 deletion tests/compiler/unsafe.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"--noUnsafe"
],
"stderr": [
"AS212: Decorator '@unsafe' is not valid here.",
"AS101: Operation is unsafe.", "f1();",
"AS101: Operation is unsafe.", "f2();",
"AS101: Operation is unsafe.", "= new Foo();",
Expand Down
4 changes: 0 additions & 4 deletions tests/compiler/unsafe.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Global

@unsafe var g = 0; // not valid here

// Function

@unsafe function f1(): void {}
Expand Down

0 comments on commit 89b49f0

Please sign in to comment.