44 lines
1.2 KiB
Plaintext
44 lines
1.2 KiB
Plaintext
// issue-0004: scalar-to-vector conversion when all optional struct fields are null
|
|
//
|
|
// When a struct has multiple ?f32 fields and ALL are set to null simultaneously,
|
|
// passing that struct to a virtual function call triggers:
|
|
// "error: scalar-to-vector conversion failed"
|
|
//
|
|
// Setting at least one field to a concrete value works fine.
|
|
|
|
#import "modules/std.sx";
|
|
|
|
ProposedSize :: struct {
|
|
width: ?f32;
|
|
height: ?f32;
|
|
}
|
|
|
|
Sizable :: protocol {
|
|
size :: (proposal: ProposedSize) -> f32;
|
|
}
|
|
|
|
Widget :: struct {}
|
|
|
|
impl Sizable for Widget {
|
|
size :: (self: *Widget, proposal: ProposedSize) -> f32 {
|
|
w := if pw := proposal.width { pw; } else { 100.0; };
|
|
h := if ph := proposal.height { ph; } else { 100.0; };
|
|
w + h;
|
|
}
|
|
}
|
|
|
|
main :: () -> void {
|
|
w := Widget.{};
|
|
s : Sizable = w;
|
|
|
|
// These work:
|
|
r1 := s.size(ProposedSize.{ width = 50.0, height = null });
|
|
print("r1 = {}\n", r1);
|
|
r2 := s.size(ProposedSize.{ width = null, height = 50.0 });
|
|
print("r2 = {}\n", r2);
|
|
|
|
// This fails with "scalar-to-vector conversion failed":
|
|
r3 := s.size(ProposedSize.{ width = null, height = null });
|
|
print("r3 = {}\n", r3);
|
|
}
|