Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tslang/lib/TypeScript/MLIRGenFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<mlir_ts::StringType>(restBaseType)
|| isa<mlir_ts::BooleanType>(restBaseType) || isa<mlir_ts::BigIntType>(restBaseType)
|| isa<mlir_ts::CharType>(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(
Expand Down
10 changes: 10 additions & 0 deletions tslang/test/tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_FILE:tslang> --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`
Expand Down
11 changes: 11 additions & 0 deletions tslang/test/tester/diagnostic-location/rest_parameter_type.ts
Original file line number Diff line number Diff line change
@@ -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);
}
Loading