From 46529df2c4f73a4655bdd79d48004f29374a99a8 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 6 Nov 2023 14:40:38 -0800 Subject: Fix ICE when lowering an associatedtype declref from an derived interface. (#3312) * Fix ICE when lowering an associatedtype declref from an derived interface. * Fixes. * Fix test. * Fix GLSL/SPIRV image subscript swizzle store regression. * Fix. --------- Co-authored-by: Yong He --- source/slang/slang-parser.cpp | 67 +++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 24 deletions(-) (limited to 'source/slang/slang-parser.cpp') diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index e701a1c2b..8c9604df6 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -1048,7 +1048,7 @@ namespace Slang } template - bool tryParseUsingSyntaxDecl( + bool tryParseUsingSyntaxDeclImpl( Parser* parser, SyntaxDecl* syntaxDecl, T** outSyntax) @@ -1068,12 +1068,24 @@ namespace Slang return false; } - auto syntax = as(parsedObject); + auto innerParsedObject = parsedObject; + auto genericDecl = as(parsedObject); + if (genericDecl) + innerParsedObject = genericDecl->inner; + + auto syntax = as(innerParsedObject); if (syntax) { if (!syntax->loc.isValid()) { syntax->loc = keywordToken.loc; + if (genericDecl) + { + genericDecl->nameAndLoc.loc = syntax->loc; + genericDecl->loc = syntax->loc; + } + if (auto decl = as(syntax)) + decl->nameAndLoc.loc = syntax->loc; } } else if (parsedObject) @@ -1082,8 +1094,12 @@ namespace Slang SLANG_DIAGNOSE_UNEXPECTED(parser->sink, keywordToken, "parser callback did not return the expected type"); } - *outSyntax = syntax; - return true; + if (auto converted = as(parsedObject)) + { + *outSyntax = converted; + return true; + } + return false; } template @@ -1102,7 +1118,7 @@ namespace Slang if (!syntaxDecl) return false; - return tryParseUsingSyntaxDecl(parser, syntaxDecl, outSyntax); + return tryParseUsingSyntaxDeclImpl(parser, syntaxDecl, outSyntax); } static Modifiers ParseModifiers(Parser* parser) @@ -3285,31 +3301,34 @@ namespace Slang { ConstructorDecl* decl = parser->astBuilder->create(); - // Note: we leave the source location of this decl as invalid, to - // trigger the fallback logic that fills in the location of the - // `__init` keyword later. + return parseOptGenericDecl(parser, [&](GenericDecl*) + { + // Note: we leave the source location of this decl as invalid, to + // trigger the fallback logic that fills in the location of the + // `__init` keyword later. - parser->PushScope(decl); + parser->PushScope(decl); - // TODO: we need to make sure that all initializers have - // the same name, but that this name doesn't conflict - // with any user-defined names. - // Giving them a name (rather than leaving it null) - // ensures that we can use name-based lookup to find - // all of the initializers on a type (and has - // the potential to unify initializer lookup with - // ordinary member lookup). - decl->nameAndLoc.name = getName(parser, "$init"); + // TODO: we need to make sure that all initializers have + // the same name, but that this name doesn't conflict + // with any user-defined names. + // Giving them a name (rather than leaving it null) + // ensures that we can use name-based lookup to find + // all of the initializers on a type (and has + // the potential to unify initializer lookup with + // ordinary member lookup). + decl->nameAndLoc.name = getName(parser, "$init"); - parseParameterList(parser, decl); + parseParameterList(parser, decl); - decl->body = parseOptBody(parser); + decl->body = parseOptBody(parser); - if (auto block = as(decl->body)) - decl->closingSourceLoc = block->closingSourceLoc; + if (auto block = as(decl->body)) + decl->closingSourceLoc = block->closingSourceLoc; - parser->PopScope(); - return decl; + parser->PopScope(); + return decl; + }); } static AccessorDecl* parseAccessorDecl(Parser* parser) -- cgit v1.2.3