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 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'source/slang/slang-check-type.cpp') 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; -- cgit v1.2.3