diff options
| author | Copilot <198982749+Copilot@users.noreply.github.com> | 2025-07-15 17:42:43 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-16 00:42:43 +0000 |
| commit | 652a8ee6883f08ce7cb55ef372277a535ce4d88f (patch) | |
| tree | 856308f1cd3089408046c3d41cf2b5e7bfa2d19e | |
| parent | 21a66267c661a55c8ad27248c0765276dd6f72ea (diff) | |
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>
| -rw-r--r-- | source/slang/slang-check-decl.cpp | 12 | ||||
| -rw-r--r-- | source/slang/slang-diagnostic-defs.h | 5 | ||||
| -rw-r--r-- | tests/diagnostics/generic-value-parameter-float-type.slang | 41 |
3 files changed, 58 insertions, 0 deletions
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( diff --git a/tests/diagnostics/generic-value-parameter-float-type.slang b/tests/diagnostics/generic-value-parameter-float-type.slang new file mode 100644 index 000000000..0f9cde255 --- /dev/null +++ b/tests/diagnostics/generic-value-parameter-float-type.slang @@ -0,0 +1,41 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): -target spirv + +// Test that generic value parameters with float types are properly rejected + +// CHECK: error 30624: generic value parameter type 'float' is not supported +struct ColorDefiner<let TMult : float> +{ + float4 color = {0.3, 0.7, 0.55, 1.0}; + + float4 get_color() { return color * TMult; } +} + +// CHECK: error 30624: generic value parameter type 'double' is not supported +struct DoubleDefiner<let TMult : double> +{ + float4 color = {0.3, 0.7, 0.55, 1.0}; + + float4 get_color() { return color * float(TMult); } +} + +// Integer types should work fine (no error expected) +struct IntDefiner<let TMult : int> +{ + float4 color = {0.3, 0.7, 0.55, 1.0}; + + float4 get_color() { return color * TMult; } +} + +// Enum types should work fine (no error expected) +enum Color { Red = 1, Green = 2, Blue = 3 } + +struct EnumDefiner<let TMult : Color> +{ + float4 color = {0.3, 0.7, 0.55, 1.0}; + + float4 get_color() { return color * int(TMult); } +} + +void computeMain() +{ +}
\ No newline at end of file |
