From 652a8ee6883f08ce7cb55ef372277a535ce4d88f Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 15 Jul 2025 17:42:43 -0700 Subject: Add clear diagnostic for unsupported float types in generic value parameters (#7737) * Initial plan * Add validation and clear error message for float generic parameters Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> --- source/slang/slang-check-decl.cpp | 12 ++++++++++++ source/slang/slang-diagnostic-defs.h | 5 +++++ 2 files changed, 17 insertions(+) (limited to 'source') diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 584b1f081..9853b0097 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -3413,6 +3413,18 @@ void SemanticsDeclHeaderVisitor::visitGenericTypeParamDecl(GenericTypeParamDecl* void SemanticsDeclHeaderVisitor::visitGenericValueParamDecl(GenericValueParamDecl* decl) { checkVarDeclCommon(decl); + + // Validate that the type is supported for generic value parameters + if (decl->type.type) + { + if (!isValidCompileTimeConstantType(decl->type.type)) + { + getSink()->diagnose( + decl, + Diagnostics::genericValueParameterTypeNotSupported, + decl->type.type); + } + } } void SemanticsDeclHeaderVisitor::visitGenericDecl(GenericDecl* genericDecl) diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h index fdfa968c3..c549ccca3 100644 --- a/source/slang/slang-diagnostic-defs.h +++ b/source/slang/slang-diagnostic-defs.h @@ -1704,6 +1704,11 @@ DIAGNOSTIC( Error, genericValueParameterMustHaveType, "a generic value parameter must be given an explicit type") +DIAGNOSTIC( + 30624, + Error, + genericValueParameterTypeNotSupported, + "generic value parameter type '$0' is not supported; only integer and enum types are allowed") // 307xx: parameters DIAGNOSTIC( -- cgit v1.2.3