diff options
| author | Darren Wihandi <65404740+fairywreath@users.noreply.github.com> | 2025-01-24 16:12:38 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-24 13:12:38 -0800 |
| commit | 92c9fffb95c92b0bc07eb1c656375928b5cd5c33 (patch) | |
| tree | 7faf537e1d56a22cd8e16133867da745b32b2aef /source | |
| parent | ac174d260d90b66ebbc8264001a75b9527611cbc (diff) | |
improve error message on generic value decls (#6169)
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-ast-support-types.h | 1 | ||||
| -rw-r--r-- | source/slang/slang-check-decl.cpp | 9 | ||||
| -rw-r--r-- | source/slang/slang-diagnostic-defs.h | 6 | ||||
| -rw-r--r-- | source/slang/slang-syntax.cpp | 13 |
4 files changed, 26 insertions, 3 deletions
diff --git a/source/slang/slang-ast-support-types.h b/source/slang/slang-ast-support-types.h index 1d3de9c54..56e07d430 100644 --- a/source/slang/slang-ast-support-types.h +++ b/source/slang/slang-ast-support-types.h @@ -80,6 +80,7 @@ class SyntaxNode; SourceLoc getDiagnosticPos(SyntaxNode const* syntax); SourceLoc getDiagnosticPos(TypeExp const& typeExp); SourceLoc getDiagnosticPos(DeclRefBase* declRef); +SourceLoc getDiagnosticPos(Decl* decl); typedef NodeBase* (*SyntaxParseCallback)(Parser* parser, void* userData); diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 0319eb260..3453d0538 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -1775,7 +1775,14 @@ void SemanticsDeclHeaderVisitor::checkVarDeclCommon(VarDeclBase* varDecl) { if (!varDecl->type.type) { - getSink()->diagnose(varDecl, Diagnostics::varWithoutTypeMustHaveInitializer); + if (as<GenericValueParamDecl>(varDecl)) + { + getSink()->diagnose(varDecl, Diagnostics::genericValueParameterMustHaveType); + } + else + { + getSink()->diagnose(varDecl, Diagnostics::varWithoutTypeMustHaveInitializer); + } varDecl->type.type = m_astBuilder->getErrorType(); } } diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h index ca99ac11d..37dfc8114 100644 --- a/source/slang/slang-diagnostic-defs.h +++ b/source/slang/slang-diagnostic-defs.h @@ -1421,7 +1421,11 @@ DIAGNOSTIC( ambiguousDefaultInitializerForType, "more than one default initializer was found for type '$0'") DIAGNOSTIC(30623, Error, cannotHaveInitializer, "'$0' cannot have an initializer because it is $1") - +DIAGNOSTIC( + 30623, + Error, + genericValueParameterMustHaveType, + "a generic value parameter must be given an explicit type") // 307xx: parameters DIAGNOSTIC( diff --git a/source/slang/slang-syntax.cpp b/source/slang/slang-syntax.cpp index 6fdd5088a..e479f1b9d 100644 --- a/source/slang/slang-syntax.cpp +++ b/source/slang/slang-syntax.cpp @@ -284,7 +284,18 @@ SourceLoc getDiagnosticPos(DeclRefBase* declRef) { if (!declRef) return SourceLoc(); - return declRef->getDecl()->loc; + return getDiagnosticPos(declRef->getDecl()); +} + +SourceLoc getDiagnosticPos(Decl* decl) +{ + if (!decl) + return SourceLoc(); + if (decl->getNameLoc().isValid()) + { + return decl->getNameLoc(); + } + return decl->loc; } // !!!!!!!!!!!!!!!!!!!!!!!!!!!!! Free functions !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
