diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2023-07-07 03:52:00 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-06 15:52:00 -0400 |
| commit | cdfea42f1b28c6ec7b13500a64be823f67bf8e0a (patch) | |
| tree | 4444c21ac369ce8f4c99370fcd47153eeb35581f /source/slang/slang-lookup.cpp | |
| parent | 4a88139a86596fd1a546af84ab3210ea3013c58d (diff) | |
Fix erroneous error claiming variable is being used before its declaration (#2958)
* Simplify type of diagnoseImpl
* Show source line for Note diagnostics, opting out of this where appropriate
* Make declared after use diagnostic clearer
* Fix erroneous error claiming variable is being used before its declaration
Closes https://github.com/shader-slang/slang/issues/2936
* Fix build on msvc
---------
Co-authored-by: jsmall-nvidia <jsmall@nvidia.com>
Diffstat (limited to 'source/slang/slang-lookup.cpp')
| -rw-r--r-- | source/slang/slang-lookup.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/source/slang/slang-lookup.cpp b/source/slang/slang-lookup.cpp index 0c4279761..46977b71d 100644 --- a/source/slang/slang-lookup.cpp +++ b/source/slang/slang-lookup.cpp @@ -139,6 +139,13 @@ static void _lookUpMembersInValue( LookupResult& ioResult, BreadcrumbInfo* breadcrumbs); +static bool _isUncheckedLocalVar(const Decl* decl) +{ + auto checkStateExt = decl->checkState; + auto isUnchecked = checkStateExt.getState() == DeclCheckState::Unchecked || checkStateExt.isBeingChecked(); + return isUnchecked && isLocalVar(decl); +} + /// Look up direct members (those declared in `containerDeclRef` itself, as well /// as transitively through any direct members that are marked "transparent." /// @@ -162,6 +169,8 @@ static void _lookUpDirectAndTransparentMembers( // return all the members that are available. for (auto member : containerDecl->members) { + if(!request.shouldConsiderAllLocalNames() && _isUncheckedLocalVar(member)) + continue; if (!DeclPassesLookupMask(member, request.mask)) continue; AddToLookupResult( @@ -182,6 +191,12 @@ static void _lookUpDirectAndTransparentMembers( // type declarations. for (auto m = firstDecl; m; m = m->nextInContainerWithSameName) { + // Skip this declaration if we are checking and this hasn't been + // checked yet. Because we traverse block statements in order, if + // it's unchecked or being checked then it isn't declared yet. + if(!request.shouldConsiderAllLocalNames() && _isUncheckedLocalVar(m)) + continue; + if (!DeclPassesLookupMask(m, request.mask)) continue; @@ -948,10 +963,14 @@ LookupResult lookUp( SemanticsVisitor* semantics, Name* name, Scope* scope, - LookupMask mask) + LookupMask mask, + bool considerAllLocalNamesInScope) { LookupResult result; - LookupRequest request = initLookupRequest(semantics, name, mask, LookupOptions::None, scope); + const auto options = considerAllLocalNamesInScope + ? LookupOptions::ConsiderAllLocalNamesInScope + : LookupOptions::None; + LookupRequest request = initLookupRequest(semantics, name, mask, options, scope); _lookUpInScopes(astBuilder, name, request, result); return result; } |
