Skip to content

Commit cbdee1b

Browse files
author
Tim Foley
authored
Fix front-end handling of generic static methods (shader-slang#1319)
* Fix front-end handling of generic static methods The front-end logic that was testing if a member was usable as a static member neglected to unwrap any generic-ness and look at the declaration inside (the parser currently puts all modifiers on the inner declaration instead of the outer generic). The test case included here is not a full compute test so that it only runs the front-end checking logic (where we had the bug). * fixup: tabs->spaces
1 parent 79f6a01 commit cbdee1b

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

source/slang/slang-check-decl.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,9 @@ namespace Slang
539539
bool SemanticsVisitor::isDeclUsableAsStaticMember(
540540
Decl* decl)
541541
{
542+
if(auto genericDecl = as<GenericDecl>(decl))
543+
decl = genericDecl->inner;
544+
542545
if(decl->HasModifier<HLSLStaticModifier>())
543546
return true;
544547

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// generic-static-method.slang
2+
3+
// Confirm that the compiler can handle a generic
4+
// `static` method declaration and call.
5+
6+
//TEST:SIMPLE:
7+
8+
interface IFrobnicator
9+
{
10+
float frobnicate(float value);
11+
}
12+
13+
struct Doubler : IFrobnicator
14+
{
15+
float frobnicate(float value) { return 2.0f * value; }
16+
}
17+
18+
struct FrobnicateHelpers
19+
{
20+
static float doubleFrobnicate<F : IFrobnicator>(F f, float value)
21+
{
22+
return f.frobnicate(f.frobnicate(value));
23+
}
24+
}
25+
26+
float test(float value)
27+
{
28+
Doubler d;
29+
return FrobnicateHelpers.doubleFrobnicate(d, value);
30+
}

0 commit comments

Comments
 (0)