diff options
| -rw-r--r-- | source/slang/slang-check-shader.cpp | 28 | ||||
| -rw-r--r-- | source/slang/slang-ir-specialize.cpp | 7 |
2 files changed, 29 insertions, 6 deletions
diff --git a/source/slang/slang-check-shader.cpp b/source/slang/slang-check-shader.cpp index c588a9018..731619908 100644 --- a/source/slang/slang-check-shader.cpp +++ b/source/slang/slang-check-shader.cpp @@ -1216,16 +1216,36 @@ namespace Slang auto specializationArg = args[ii]; genericArgs.add(specializationArg.val); } - ASTBuilder* astBuilder = getLinkage()->getASTBuilder(); - + auto astBuilder = getLinkage()->getASTBuilder(); for (auto constraintDecl : getMembersOfType<GenericTypeConstraintDecl>( getLinkage()->getASTBuilder(), DeclRef<ContainerDecl>(genericDeclRef))) { DeclRef<GenericTypeConstraintDecl> constraintDeclRef = astBuilder->getDirectDeclRef(constraintDecl.getDecl()); + int argIndex = -1; + int ii = 0; + for (auto member : genericDeclRef.getDecl()->members) + { + if (member == constraintDeclRef.getDecl()) + { + argIndex = ii; + break; + } + ii++; + } + if (argIndex == -1) + { + SLANG_ASSERT(!"generic parameter not found in generic decl"); + continue; + } - auto sub = getSub(astBuilder, constraintDeclRef); - auto sup = getSup(astBuilder, constraintDeclRef); + auto sub = as<Type>(args[argIndex].val); + if (!sub) + { + sink->diagnose(constraintDecl, Diagnostics::expectedTypeForSpecializationArg, argIndex); + continue; + } + auto sup = getSup(astBuilder, constraintDeclRef); auto subTypeWitness = visitor.isSubtype(sub, sup); if(subTypeWitness) { diff --git a/source/slang/slang-ir-specialize.cpp b/source/slang/slang-ir-specialize.cpp index 3320a7d09..a4985eee4 100644 --- a/source/slang/slang-ir-specialize.cpp +++ b/source/slang/slang-ir-specialize.cpp @@ -2381,9 +2381,12 @@ IRInst* specializeGenericImpl( // further specializations from the specialized function will have as simple specialization // arguments as possible to avoid creating specializations that eventually simplified into // the same thing. - if (auto func = as<IRFunc>(specializedVal)) + if (context) { - simplifyFunc(context->targetProgram, func, IRSimplificationOptions::getFast()); + if (auto func = as<IRFunc>(specializedVal)) + { + simplifyFunc(context->targetProgram, func, IRSimplificationOptions::getFast()); + } } return specializedVal; |
