Skip to content

Commit 89b49f0

Browse files
committed
Report errors from initialize
This is unfortunately necessary for the next commit. This is overall bad for DX, since fewer errors are shown to the user at once.
1 parent d142ac8 commit 89b49f0

15 files changed

+54
-43
lines changed

cli/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,12 @@ export async function main(argv, options) {
716716
}
717717
stats.initializeTime += stats.end(begin);
718718
}
719+
let numErrors = checkDiagnostics(program, stderr, opts.disableWarning, options.reportDiagnostic, stderrColors.enabled);
720+
if (numErrors) {
721+
const err = Error(`${numErrors} initialize error(s)`);
722+
err.stack = err.message; // omit stack
723+
return prepareResult(err);
724+
}
719725

720726
// Call afterInitialize transform hook
721727
{
@@ -740,7 +746,7 @@ export async function main(argv, options) {
740746
? assemblyscript.getBinaryenModuleRef(module)
741747
: module.ref
742748
);
743-
let numErrors = checkDiagnostics(program, stderr, opts.disableWarning, options.reportDiagnostic, stderrColors.enabled);
749+
numErrors = checkDiagnostics(program, stderr, opts.disableWarning, options.reportDiagnostic, stderrColors.enabled);
744750
if (numErrors) {
745751
const err = Error(`${numErrors} compile error(s)`);
746752
err.stack = err.message; // omit stack

tests/compiler/covariance.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"stderr": [
3+
"TS2394: This overload signature is not compatible with its implementation signature.",
4+
"sibling: Cat | null;",
5+
"sibling: Animal | null;"
6+
]
7+
}

tests/compiler/covariance.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Animal {
2+
sibling: Animal | null;
3+
}
4+
5+
class Cat extends Animal {
6+
sibling: Cat | null; // covariance is unsound
7+
}
8+
9+
new Cat();

tests/compiler/duplicate-field-errors.json

+2-8
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@
33
],
44
"stderr": [
55
"TS2385: Overload signatures must all be public, private or protected.", "public privPub: i32;", "private privPub: i32;",
6-
"TS2442: Types have separate declarations of a private property 'privPriv'.",
7-
"TS2325: Property 'privProt' is private in type 'duplicate-field-errors/A' but not in type 'duplicate-field-errors/B'.",
8-
"TS2325: Property 'privPub' is private in type 'duplicate-field-errors/A' but not in type 'duplicate-field-errors/B'.",
9-
"TS2325: Property 'protPriv' is private in type 'duplicate-field-errors/B' but not in type 'duplicate-field-errors/A'.",
10-
"TS2325: Property 'pubPriv' is private in type 'duplicate-field-errors/B' but not in type 'duplicate-field-errors/A'.",
11-
"TS2444: Property 'pubProt' is protected in type 'duplicate-field-errors/B' but public in type 'duplicate-field-errors/A'.",
12-
"TS2394: This overload signature is not compatible with its implementation signature.", "public method: i32;", "method(): void",
13-
"TS2394: This overload signature is not compatible with its implementation signature.", "sibling: Cat | null;", "sibling: Animal | null;"
6+
"TS2385: Overload signatures must all be public, private or protected.", "protected pubProt: i32;", "public pubProt: i32;",
7+
"TS2416: Property 'method' in type 'duplicate-field-errors/B' is not assignable to the same property in base type 'duplicate-field-errors/A'."
148
]
159
}

tests/compiler/duplicate-field-errors.ts

-8
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,7 @@ class B extends A {
3636
public method: i32;
3737
}
3838

39-
class Animal {
40-
sibling: Animal | null;
41-
}
42-
class Cat extends Animal {
43-
sibling: Cat | null; // covariance is unsound
44-
}
45-
4639
export function test(): void {
4740
new A();
4841
new B();
49-
new Cat();
5042
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"stderr": [
3+
"TS2300: Duplicate identifier 'e'", "var e: f32", "var e: i32",
4+
"TS2300: Duplicate identifier 'f'", "let f: f32",
5+
"EOF"
6+
]
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function baz(): void {
2+
var e: i32;
3+
var e: f32;
4+
{
5+
let f: i32;
6+
let f: f32;
7+
}
8+
}
9+
10+
baz();
11+
12+
ERROR("EOF"); // mark end and ensure fail

tests/compiler/duplicate-identifier.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
"TS2300: Duplicate identifier 'a'", "var a: f32", "var a: i32",
66
"TS2300: Duplicate identifier 'b'", "b: f32", "b: i32",
77
"TS2300: Duplicate identifier 'c'", "static c: f32", " static c: i32",
8-
"TS2300: Duplicate identifier 'd'", "const d: f32", "const d: i32",
9-
"TS2300: Duplicate identifier 'e'", "var e: f32", "var e: i32",
10-
"TS2300: Duplicate identifier 'f'", "let f: f32",
11-
"EOF"
8+
"TS2300: Duplicate identifier 'd'", "const d: f32", "const d: i32"
129
]
1310
}

tests/compiler/duplicate-identifier.ts

-13
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,3 @@ namespace Bar {
1212
const d: i32 = 0;
1313
const d: f32 = 1;
1414
}
15-
16-
function baz(): void {
17-
var e: i32;
18-
var e: f32;
19-
{
20-
let f: i32;
21-
let f: f32;
22-
}
23-
}
24-
25-
baz();
26-
27-
ERROR("EOF"); // mark end and ensure fail

tests/compiler/unmanaged-errors.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
],
44
"stderr": [
55
"AS207: Unmanaged classes cannot extend managed classes and vice-versa.", "UnmanagedFoo extends ManagedBase",
6-
"AS207: Unmanaged classes cannot extend managed classes and vice-versa.", "ManagedFoo extends UnmanagedBase",
7-
"EOF"
6+
"AS207: Unmanaged classes cannot extend managed classes and vice-versa.", "ManagedFoo extends UnmanagedBase"
87
]
98
}

tests/compiler/unmanaged-errors.ts

-2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,3 @@ class ManagedBaz {}
88
class ManagedFoo extends UnmanagedBase { // AS207
99
constructor(public baz: ManagedBaz) { super(); }
1010
}
11-
12-
ERROR("EOF");

tests/compiler/unsafe-not-valid.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"stderr": [
3+
"AS212: Decorator '@unsafe' is not valid here."
4+
]
5+
}

tests/compiler/unsafe-not-valid.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Global
2+
3+
@unsafe var g = 0; // not valid here

tests/compiler/unsafe.json

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"--noUnsafe"
44
],
55
"stderr": [
6-
"AS212: Decorator '@unsafe' is not valid here.",
76
"AS101: Operation is unsafe.", "f1();",
87
"AS101: Operation is unsafe.", "f2();",
98
"AS101: Operation is unsafe.", "= new Foo();",

tests/compiler/unsafe.ts

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// Global
2-
3-
@unsafe var g = 0; // not valid here
4-
51
// Function
62

73
@unsafe function f1(): void {}

0 commit comments

Comments
 (0)