Skip to content

Conversation

@Graveflo
Copy link
Contributor

@Graveflo Graveflo commented Nov 23, 2025

#25290
drafted bc if this passes full CI I am going to try and remove that weird stuff in pickBestCandidate

@Graveflo Graveflo marked this pull request as draft November 23, 2025 07:13
@Graveflo
Copy link
Contributor Author

Graveflo commented Nov 24, 2025

some background on this:

discard not (let xx = 1; true)
discard xx

Here, xx has to get added to scope, but only if the best candidate from overload resolution is not a macro or template. This logic is correctly implemented here:

Nim/compiler/sigmatch.nim

Lines 3024 to 3027 in 6543040

if m.state == csMatch and not (m.calleeSym != nil and m.calleeSym.kind in {skTemplate, skMacro}):
c.mergeShadowScope
else:
c.closeShadowScope

The problem is, once we check the first overload in matchesAux the operand expression gets sem'd (I'm assuming) so it is not added to the shadow scope in further trials. This line looks like a bad hack to get around this:

c.mergeShadowScope #merge so that we don't have to resem for later overloads

The way it is currently set up, matches needs to know if the best overload will be a template or macro, but that has not been determined yet, so the logic was moved to pickBestCandidate. Since the scope is merged without much care in matches currently, this might be safe.

As of writing, measuremancer is failing the CI and the issue is tricky to trace. Still not sure what is wong:

import unchained, measuremancer
let x = 2.0.m ± 0.2.m
defUnit(Meter⁻²)
echo typeof(x)
discard x ** (-2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant