diff options
| author | Yong He <yonghe@outlook.com> | 2024-04-02 11:51:36 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-02 11:51:36 -0700 |
| commit | b5f4cf63a8b952731053a0d04af0fc8c946d86f3 (patch) | |
| tree | 5ff2c4fc31a9c6728d7e0af6b60d9b7c074c7a81 /source/slang/slang-check-expr.cpp | |
| parent | 251f55c5ec4cb2b7432e71d6ba8adc96700d35c2 (diff) | |
Allow enum values to be used as generic arguments. (#3874)
* Allow enum values to be used as generic arguments.
* Fix constant folding.
Diffstat (limited to 'source/slang/slang-check-expr.cpp')
| -rw-r--r-- | source/slang/slang-check-expr.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index d3341e87b..ff5dd4af5 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -1768,7 +1768,10 @@ namespace Slang return nullptr; ConstantFoldingCircularityInfo newCircularityInfo(enumCaseDecl, circularityInfo); - return tryConstantFoldExpr(tagExpr, kind, &newCircularityInfo); + auto intVal = as<IntVal>(tryConstantFoldExpr(tagExpr, kind, &newCircularityInfo)); + if (!intVal) + return nullptr; + return as<IntVal>(m_astBuilder->getTypeCastIntVal(enumCaseDecl->getType(), intVal)->resolve()); } } } @@ -1778,7 +1781,7 @@ namespace Slang auto substType = getType(m_astBuilder, expr); if (!substType) return nullptr; - if (!isScalarIntegerType(substType)) + if (!isValidCompileTimeConstantType(substType)) return nullptr; auto val = tryConstantFoldExpr(getArg(castExpr, 0), kind, circularityInfo); if (val) @@ -1826,7 +1829,7 @@ namespace Slang { // Check if type is acceptable for an integer constant expression // - if(!isScalarIntegerType(getType(m_astBuilder, expr))) + if(!isValidCompileTimeConstantType(getType(m_astBuilder, expr))) return nullptr; // Consider operations that we might be able to constant-fold... |
