You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Edit: Forgot there is only ever 1 depth of generic aliases, what I wrote wouldn't work very well. Only the final generic alias or the original generic type can be considered, i.e.:
B is inaccessible here because the Bar[123] type is removed in handleGenericInvocation, the final type of x is Baz[123] = Foo[123]. We can still make it check both Baz and Foo, probably Foo first for compatibility, but this would be a weird rule.
You might want to use a distinct type like Foo[D: static int; T] = distinct Option[D] instead. Generic aliases tend to break in edge cases like #10220.
Maybe we can recursively check each generic alias before skipping, i.e.:
typeFoo[A, B: staticint] =objectBar[A: staticint] =Foo[A, A *2]
Baz=Bar[123]
var x: Bazecho x.A
echo x.B
Baz is an alias type, so it's skipped, then it checks if Bar has a param named A or B and uses it if it does, otherwise it skips again to Foo to check if it has the param, so on so forth. This might break code though so instead we could also check from the bottom up.
Nim Version
Nim Compiler Version 2.3.1 [Linux: amd64]
Compiled at 2025-02-28
Copyright (c) 2006-2025 by Andreas Rumpf
git hash: 7e8a650
active boot switches: -d:release
Description
When accessing a generic field from a generic alias it only allows accessing what it aliases.
The
Foo
example is a bit more useful since it allows you to attach metadata to types without needing to resort to macros.Current Output
Expected Output
Known Workarounds
No response
Additional Information
I've tracked the issue down to when it calls readTypeParameter it just skips past the alias if both are generics and so the fields on the alias cant be accessed (unless they share the same name)
The text was updated successfully, but these errors were encountered: