-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Segmentation fault, caused indirectly, by using mut x := []X{ len: positive }
, where X is sumtype or interface
#20272
Comments
pub fn maybe_map[T, X](a []T, f fn(T) !X) ![]X {
mut r := []X{len: a.len} // =====> mut r := []X{cap: a.len} cap
for v in a {
r << f(v)!
}
return r
} A NULL reference element at the beginning of the array causes a segment fault |
|
@shove70, I think, that it is still a valid bug, since the problem is, that: I think that in those cases, it should require I also think, that we should think about how to provide a way to specify the defaults for sumtype values and interfaces. @medvednikov what do you think? |
mut x := []X{ len: positive }
, where X is sumtype or interface
Yeah, yeah, that's right! 👍 |
There are already 2 related test cases, but it is not triggered |
@spytheman , how about an attribute that indicates the default value to use? @[default_value: SumType(5)]
type SumType = int | string
@[default_value: Iface(IfaceEmpty{})
interface Iface {}
struct IfaceEmpty {} |
The first variant’s zero value as default, It seems pretty good too |
I think, interfaces should not be considered, because interfaces are an abstraction, and the current "disallow empty interface initialization" approach can be left intact, |
Describe the bug
<title>Reproduction Steps
Expected Behavior
Successful execution, and successful asserts
Current Behavior
Possible Solution
No response
Additional Information/Context
No response
V version
V 0.4.3 30d6f7b
Environment details (OS name and version, etc.)
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
The text was updated successfully, but these errors were encountered: