-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
templates/macros use no expected types when return types are specified #24298
Conversation
It seems to break templates that present int literals: Before my PR, the type inference seemed to treat int literals differently: block: # bug #24295
template g(_: int): int = 12
proc foo(x: uint, y: uint) =
echo (x, y)
let c: uint = 0.g() # type mismatch: got 'uint' for '12' but expected 'int'
foo(12, g(0)) # compiles
block:
proc foe(): int = 12
proc foo(x: uint, y: uint) =
echo (x, y)
let c: uint = foe() # type mismatch: got 'int' for 'foe()' but expected 'uint'
foo(12, foe()) # type mismatch: got 'int' for 'foe()' but expected 'uint'
|
It seems that in old Nim versions, templates just inline expressions without annotating the int literals with types |
Thanks for your hard work on this PR! Hint: mm: orc; opt: speed; options: -d:release |
#24298) fixes #24296 fixes #24295 Templates use `expectedType` for type inference. It's justified that when templates don't have an actual return type, i.e., `untyped` etc. When the return type of templates is specified, we should not infer the type ```nim template g(): string = "" let c: cstring = g() ``` In this example, it is not reasonable to annotate the templates expression with the `cstring` type before the `fitNode` check with its specified return type. (cherry picked from commit 80e6b35)
#24298) fixes #24296 fixes #24295 Templates use `expectedType` for type inference. It's justified that when templates don't have an actual return type, i.e., `untyped` etc. When the return type of templates is specified, we should not infer the type ```nim template g(): string = "" let c: cstring = g() ``` In this example, it is not reasonable to annotate the templates expression with the `cstring` type before the `fitNode` check with its specified return type. (cherry picked from commit 80e6b35)
fixes #24296
fixes #24295
Templates use
expectedType
for type inference. It's justified that when templates don't have an actual return type, i.e.,untyped
etc.When the return type of templates is specified, we should not infer the type
In this example, it is not reasonable to annotate the templates expression with the
cstring
type before thefitNode
check with its specified return type.