Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix domination within deeply nested blocks #485

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions codon/parser/visitors/simplify/ctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,16 @@ SimplifyContext::Item SimplifyContext::findDominatingBinding(const std::string &
// We went outside the function scope. Break.
if (!isOutside && (*i)->getBaseName() != getBaseName())
break;
bool completeDomination =
(*i)->scope.size() <= scope.blocks.size() &&
(*i)->scope.back() == scope.blocks[(*i)->scope.size() - 1];
if (!completeDomination && prefix < int(scope.blocks.size()) && prefix != p) {
break;
}
prefix = p;
lastGood = i;
// The binding completely dominates the current scope. Break.
if ((*i)->scope.size() <= scope.blocks.size() &&
(*i)->scope.back() == scope.blocks[(*i)->scope.size() - 1])
if (completeDomination)
break;
}
seqassert(lastGood != it->second.end(), "corrupted scoping ({})", name);
Expand Down
32 changes: 32 additions & 0 deletions test/parser/types.codon
Original file line number Diff line number Diff line change
Expand Up @@ -1998,3 +1998,35 @@ print(Tuple[-5, int].__class__.__name__)
#: Tuple
print(Tuple[5, int, str].__class__.__name__)
#: Tuple[int,str,int,str,int,str,int,str,int,str]


#%% domination_nested,barebones
def correlate(a, b, mode = 'valid'):
if mode == 'valid':
if isinstance(a, List):
xret = '1'
else:
xret = '2'
for i in a:
for j in b:
xret += 'z'
elif mode == 'same':
if isinstance(a, List):
xret = '3'
else:
xret = '4'
for i in a:
for j in b:
xret += 'z'
elif mode == 'full':
if isinstance(a, List):
xret = '5'
else:
xret = '6'
for i in a:
for j in b:
xret += 'z'
else:
raise ValueError(f"mode must be one of 'valid', 'same', or 'full' (got {repr(mode)})")
return xret
print(correlate([1], [2], 'full')) # 5z