diff --git a/tslang/lib/TypeScript/MLIRGenClasses.cpp b/tslang/lib/TypeScript/MLIRGenClasses.cpp index 489e403b0..2caeb893b 100644 --- a/tslang/lib/TypeScript/MLIRGenClasses.cpp +++ b/tslang/lib/TypeScript/MLIRGenClasses.cpp @@ -1540,6 +1540,13 @@ namespace mlirgen }, genContext); + // a failed initializer (e.g. `null` for a `Ref`) leaves no type; going on with + // none dropped its diagnostic, since those are only shown when the module fails + if (!staticFieldType) + { + return mlir::failure(); + } + auto &staticFieldInfos = newClassPtr->staticFields; pushStaticField(staticFieldInfos, fieldId, staticFieldType, fullClassStaticFieldName, -1, accessLevel); diff --git a/tslang/test/tester/CMakeLists.txt b/tslang/test/tester/CMakeLists.txt index 5feb2e703..bc19af0fc 100644 --- a/tslang/test/tester/CMakeLists.txt +++ b/tslang/test/tester/CMakeLists.txt @@ -2939,6 +2939,14 @@ add_test(NAME test-compile-diagnostic-location-field-initializer set_tests_properties(test-compile-diagnostic-location-field-initializer PROPERTIES PASS_REGULAR_EXPRESSION "field_initializer\\.ts:6:5: error: can't cast from 'null' to 'Reference'" FAIL_REGULAR_EXPRESSION "Stack dump|Assertion failed|field_initializer\\.ts:1:") +# A static field's initializer is checked like an instance field's: it compiled with no error at all. +add_test(NAME test-compile-diagnostic-location-static-field-initializer + COMMAND $ --emit=obj --no-default-lib -mm=none + "${PROJECT_SOURCE_DIR}/test/tester/diagnostic-location/static_field_initializer.ts" + -o "${CMAKE_CURRENT_BINARY_DIR}/diagnostic-location-static-field-initializer.obj") +set_tests_properties(test-compile-diagnostic-location-static-field-initializer + PROPERTIES PASS_REGULAR_EXPRESSION "static_field_initializer\\.ts:6:32: error: can't cast from 'null' to 'Reference' in 'strict null mode'" + FAIL_REGULAR_EXPRESSION "Stack dump|Assertion failed|static_field_initializer\\.ts:1:") add_test(NAME test-compile-diagnostic-location-implicit-constructor COMMAND $ --emit=obj --no-default-lib -mm=none "${PROJECT_SOURCE_DIR}/test/tester/diagnostic-location/implicit_constructor.ts" diff --git a/tslang/test/tester/diagnostic-location/static_field_initializer.ts b/tslang/test/tester/diagnostic-location/static_field_initializer.ts new file mode 100644 index 000000000..9ddae4d3b --- /dev/null +++ b/tslang/test/tester/diagnostic-location/static_field_initializer.ts @@ -0,0 +1,7 @@ +// A static field's failed initializer compiled with no diagnostic: the field was registered +// without a type, and the error, postponed like every message, was never shown. + +class Args { + static count = 1; + static argv: Ref = null; +}