Nim icon indicating copy to clipboard operation
Nim copied to clipboard

fixes #25290; tempalte overload scope dupe

Open Graveflo opened this issue 1 month ago • 1 comments

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

Graveflo avatar Nov 23 '25 07:11 Graveflo

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:

https://github.com/nim-lang/Nim/blob/6543040d40b063ce2c872f582c153c6cff9ef0aa/compiler/sigmatch.nim#L3024-L3027

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:

https://github.com/nim-lang/Nim/blob/6543040d40b063ce2c872f582c153c6cff9ef0aa/compiler/sigmatch.nim#L2820

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)

Graveflo avatar Nov 24 '25 09:11 Graveflo