-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
kind:bugA bug in the code. Does not apply to documentation, specs, etc.A bug in the code. Does not apply to documentation, specs, etc.topic:compiler:semantic
Description
When a variable declared as an out parameter of lib call is later assigned a different type, we get memory corruption:
lib LibC
fun modf(value : Float64, iptr : Float64*) : Float64
end
LibC.modf(32.14, out foo)
foo = {foo, foo}
foo # => {0.0, 0.0}If we change the assignment to a different variable than foo, everything works as expected (value is {32.0, 32.0}).
The behaviour appears in both the compiler and interpreter, so I presume it's a semantic error.
This error came up in #16555 (comment).
I suppose a simple solution would be to disallow changing the type of an out var: out should act like a type declaration and freeze the type of the variable, making it impossible to produce any confusion.
Add a 👍 reaction to issues you find important.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
kind:bugA bug in the code. Does not apply to documentation, specs, etc.A bug in the code. Does not apply to documentation, specs, etc.topic:compiler:semantic