summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-03-24 11:42:56 -0400
committerGitHub <noreply@github.com>2022-03-24 11:42:56 -0400
commitb8617af2888db01f80efba9e0a103e6a61989c9c (patch)
tree66830e801ac0dc78180ac8d9cda8af75d59bb557 /source
parente1a331a2e2945f2b90c00d0af4d1ba5f67dbd256 (diff)
Fix for default initialization with generic field (#2168)
* #include an absolute path didn't work - because paths were taken to always be relative. * Fix for = {} initialization with a field that is generic type parameter. * Handling for if a non type is passed to a generic parameter which requires a type. * Small comment improvements. Fix some tab issues. * This fixes the matrix.slang issue. Move the matrix.slang test into bugs as generic-default-matrix.slang
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-check-type.cpp30
-rw-r--r--source/slang/slang-lower-to-ir.cpp8
2 files changed, 32 insertions, 6 deletions
diff --git a/source/slang/slang-check-type.cpp b/source/slang/slang-check-type.cpp
index 6c9b0c8ca..bd7b89e16 100644
--- a/source/slang/slang-check-type.cpp
+++ b/source/slang/slang-check-type.cpp
@@ -172,10 +172,11 @@ namespace Slang
DiagnosticSink* diagSink)
{
Type* type = typeExp.type;
- if(!type && typeExp.exp)
- {
- auto expr = typeExp.exp;
+ auto originalExpr = typeExp.exp;
+ auto expr = originalExpr;
+ if(!type && expr)
+ {
expr = maybeResolveOverloadedExpr(expr, LookupMask::type, diagSink);
if(auto typeType = as<TypeType>(expr->type))
@@ -186,6 +187,29 @@ namespace Slang
if (!type)
{
+ // Only output diagnostic if we have a sink.
+ if (diagSink)
+ {
+ // This function *can* be called with typeExp with both exp and type = nullptr.
+ // Previous behavior didn't output a diagnostic if originalExpr was null, so this keeps that behavior.
+ //
+ // Additional we check for ErrorType on expr, because if it's set a diagnostic has already been output via
+ // previous code or via maybeResolveOverloadedExpr.
+ if (originalExpr && (expr == nullptr || as<ErrorType>(expr->type) == nullptr))
+ {
+ // The diagnostic for expectedAType wants to say what it 'got'.
+ // The solution given here, currently is to just use the node name.
+ // How useful that might be could depend, and perhaps some other mechanism
+ // that catagorized 'what' the wrong thing was is. For now this seems sufficient.
+ //
+ // Note that use originalExpr (not expr) because we want original expr for diagnostic.
+
+ // Get the AST node type info, so we can output a 'got' name
+ auto info = ASTClassInfo::getInfo(originalExpr->astNodeType);
+ diagSink->diagnose(originalExpr, Diagnostics::expectedAType, info->m_name);
+ }
+ }
+
if (outProperType)
{
*outProperType = nullptr;
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp
index b2a71a2e0..9ec8c1c71 100644
--- a/source/slang/slang-lower-to-ir.cpp
+++ b/source/slang/slang-lower-to-ir.cpp
@@ -3016,15 +3016,17 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo>
UNREACHABLE_RETURN(LoweredValInfo());
}
- LoweredValInfo getDefaultVal(VarDeclBase* decl)
+ LoweredValInfo getDefaultVal(DeclRef<VarDeclBase> decl)
{
- if(auto initExpr = decl->initExpr)
+ if(auto initExpr = decl.getDecl()->initExpr)
{
return lowerRValueExpr(context, initExpr);
}
else
{
- return getDefaultVal(decl->type);
+ Type* type = decl.substitute(getASTBuilder(), decl.getDecl()->type);
+ SLANG_ASSERT(type);
+ return getDefaultVal(type);
}
}