-
-
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
Invalid codegen when unpacking tuple via template #22049
Comments
Smaller case: type A = object
field: tuple[a: int]
func value(v: var A): var tuple[a: int] =
v.field
template get(v: A): tuple[a: int] = v.value
var v = A(field: (a: 1))
echo get(v)[0]
|
A compile-time error from the C compiler is different than a runtime error which the C compiler allowed though, or? |
I'm debugging this case, probably |
True, they are different issues, I have created a new issue for the second case. |
After half day's industrious work, now It's obvious that templates implicitly convert types even though it doesn't check the types at all. A dirty workaround that disables implicit conversions for templates works like a charm, solving two issues with one stone. |
* fixes #22054; codegen for var tuples conv * rethink fixes * add test cases * templates only * fixes var tuples * keep varness no matter what * fixes typ.isNil * make it work for generics * restore isSubrange * add a test case as requested
… varness (nim-lang#22097) * fixes nim-lang#22054; codegen for var tuples conv * rethink fixes * add test cases * templates only * fixes var tuples * keep varness no matter what * fixes typ.isNil * make it work for generics * restore isSubrange * add a test case as requested
Description
this generates invalid C code where the
var
:ness of the returnedvalue
is not taken into into account because of the non-var
tuple.The result is memory corruption / crashes due to dereferencing mismatches and invalid pointer casts.
Nim Version
1.6.12
Current Output
The text was updated successfully, but these errors were encountered: