diff --git a/tslang/lib/TypeScript/MLIRGenFunctions.cpp b/tslang/lib/TypeScript/MLIRGenFunctions.cpp index ed55967de..6fe008866 100644 --- a/tslang/lib/TypeScript/MLIRGenFunctions.cpp +++ b/tslang/lib/TypeScript/MLIRGenFunctions.cpp @@ -342,6 +342,18 @@ namespace mlirgen return {mlir::failure(), isGenericTypes, params}; } + // the arguments a rest parameter takes are put in an array: one of a number type only + // failed the module's verification + auto restBaseType = mth.getBaseType(type); + if (isMultiArgs + && (mth.isNumericType(restBaseType) || isa(restBaseType) + || isa(restBaseType) || isa(restBaseType) + || isa(restBaseType))) + { + emitError(loc(arg)) << "A rest parameter must be of an array type, not '" << to_print(type) << "'"; + return {mlir::failure(), isGenericTypes, params}; + } + if (isBindingPattern) { params.push_back( diff --git a/tslang/test/tester/CMakeLists.txt b/tslang/test/tester/CMakeLists.txt index e92db2eb9..a3aab140a 100644 --- a/tslang/test/tester/CMakeLists.txt +++ b/tslang/test/tester/CMakeLists.txt @@ -2666,6 +2666,16 @@ foreach(ownership_shard RANGE ${ownership_last}) -P "${CMAKE_CURRENT_SOURCE_DIR}/verify-ownership.cmake") endforeach() +# A rest parameter of a number, string or boolean type is an error at the parameter: it reached the +# MLIR verifier, which failed the module at 1:1. +add_test(NAME test-compile-diagnostic-location-rest-parameter-type + COMMAND $ --emit=obj --no-default-lib -mm=none + "${PROJECT_SOURCE_DIR}/test/tester/diagnostic-location/rest_parameter_type.ts" + -o "${CMAKE_CURRENT_BINARY_DIR}/diagnostic-location-rest-parameter-type.obj") +set_tests_properties(test-compile-diagnostic-location-rest-parameter-type + PROPERTIES PASS_REGULAR_EXPRESSION "rest_parameter_type\\.ts:6:12: error: A rest parameter must be of an array type, not 's32'" + FAIL_REGULAR_EXPRESSION "Stack dump|Assertion failed|rest_parameter_type\\.ts:1:|rest_parameter_type\\.ts:4:|verification") + # A call with fewer arguments than the callee's required parameters is an error (TS2554), # not padded with undef. Each file in call-arity/ makes one bad call; the test passes when # the compiler prints the expected message. The counts are what the user wrote, so `this` diff --git a/tslang/test/tester/diagnostic-location/rest_parameter_type.ts b/tslang/test/tester/diagnostic-location/rest_parameter_type.ts new file mode 100644 index 000000000..fde26b30f --- /dev/null +++ b/tslang/test/tester/diagnostic-location/rest_parameter_type.ts @@ -0,0 +1,11 @@ +// A rest parameter of a number type reached the MLIR verifier, which reported the array made +// of the arguments at the call and the module at 1:1. + +function sum(...a: int[]) {} + +function f(...a: int) {} + +function main() { + sum(1, 2); + f(1, 2); +}