From b8617af2888db01f80efba9e0a103e6a61989c9c Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 24 Mar 2022 11:42:56 -0400 Subject: 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 --- source/slang/slang-check-type.cpp | 30 +++++++++++++++++++++++++++--- source/slang/slang-lower-to-ir.cpp | 8 +++++--- 2 files changed, 32 insertions(+), 6 deletions(-) (limited to 'source') 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(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(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 UNREACHABLE_RETURN(LoweredValInfo()); } - LoweredValInfo getDefaultVal(VarDeclBase* decl) + LoweredValInfo getDefaultVal(DeclRef 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); } } -- cgit v1.2.3