diff --git a/src/resolver/function_validation_test.cc b/src/resolver/function_validation_test.cc index da0a2c9fe0..d0c7556f5e 100644 --- a/src/resolver/function_validation_test.cc +++ b/src/resolver/function_validation_test.cc @@ -644,6 +644,28 @@ TEST_F(ResolverFunctionValidationTest, ParameterSotreType_AtomicFree) { EXPECT_TRUE(r()->Resolve()) << r()->error(); } +TEST_F(ResolverFunctionValidationTest, ParametersAtLimit) { + ast::VariableList params; + for (int i = 0; i < 255; i++) { + params.emplace_back(Param("param_" + std::to_string(i), ty.i32())); + } + Func(Source{{12, 34}}, "f", params, ty.void_(), {}); + + EXPECT_TRUE(r()->Resolve()) << r()->error(); +} + +TEST_F(ResolverFunctionValidationTest, ParametersOverLimit) { + ast::VariableList params; + for (int i = 0; i < 256; i++) { + params.emplace_back(Param("param_" + std::to_string(i), ty.i32())); + } + Func(Source{{12, 34}}, "f", params, ty.void_(), {}); + + EXPECT_FALSE(r()->Resolve()); + EXPECT_EQ(r()->error(), + "12:34 error: functions may declare at most 255 parameters"); +} + struct TestParams { ast::StorageClass storage_class; bool should_pass; diff --git a/src/resolver/resolver.cc b/src/resolver/resolver.cc index dd37815481..8288a3f6b4 100644 --- a/src/resolver/resolver.cc +++ b/src/resolver/resolver.cc @@ -1388,6 +1388,11 @@ bool Resolver::ValidateFunction(const ast::Function* func, } } + if (func->params().size() > 255) { + AddError("functions may declare at most 255 parameters", func->source()); + return false; + } + for (auto* param : func->params()) { if (!ValidateFunctionParameter(func, variable_to_info_.at(param))) { return false;