fixes
This commit is contained in:
43
examples/issue-0004.sx
Normal file
43
examples/issue-0004.sx
Normal file
@@ -0,0 +1,43 @@
|
||||
// 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);
|
||||
}
|
||||
Reference in New Issue
Block a user