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
Casting an option-of-sumtype field with as SumType (i.e. ?Type as Type, where Type is a sumtype) generates C that accesses the sumtype-variant members (._main__Type, ._typ) directly on the _option_main__Type option wrapper, instead of first unwrapping the option's .data. The C compiler then rejects it because the option wrapper struct has no such members.
A plain sumtype as cast (no option) compiles correctly, isolating the fault to the ?SumType as SumType case.
V version: V 0.5.1, current master (3690f882f) OS/Backend: reproduced on macOS arm64; originally reported on Linux/cc.
error: no member named '_main__Type' in 'struct _option_main__Type'
return *(main__Type*)builtin____as_cast((tf.variadic_type)._main__Type, (tf.variadic_type)._typ, 116);
error: no member named '_typ' in 'struct _option_main__Type'
The as Type cast emits (tf.variadic_type)._main__Type / (tf.variadic_type)._typ, but tf.variadic_type has type _option_main__Type (the option wrapper) — the option must be unwrapped (.data) before the sumtype-variant access.
Expected behavior
The option should be unwrapped before the sumtype as cast, so the program compiles.
Notes
Reported via the bugs.vlang.io crash reporter. Original instance: iris/checker.v, sym.type.variadic_type as Type where variadic_type is ?Type and Type is a sumtype (also surfaced as expected expression before '}' token in some report variants).
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.
Description
Casting an option-of-sumtype field with
as SumType(i.e.?Type as Type, whereTypeis a sumtype) generates C that accesses the sumtype-variant members (._main__Type,._typ) directly on the_option_main__Typeoption wrapper, instead of first unwrapping the option's.data. The C compiler then rejects it because the option wrapper struct has no such members.A plain sumtype
ascast (no option) compiles correctly, isolating the fault to the?SumType as SumTypecase.V version: V 0.5.1, current
master(3690f882f)OS/Backend: reproduced on macOS arm64; originally reported on Linux/cc.
Reproducer
Compile with:
Current behavior
The
as Typecast emits(tf.variadic_type)._main__Type/(tf.variadic_type)._typ, buttf.variadic_typehas type_option_main__Type(the option wrapper) — the option must be unwrapped (.data) before the sumtype-variant access.Expected behavior
The option should be unwrapped before the sumtype
ascast, so the program compiles.Notes
iris/checker.v,sym.type.variadic_type as Typewherevariadic_typeis?TypeandTypeis a sumtype (also surfaced asexpected expression before '}' tokenin some report variants).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.