Repository navigation
Replies: 3 comments 2 replies
|
Due to how the type system is currently projected, the comptime checking approach is brittle, leading to false negatives: |
0 replies
|
Isn't there a proposal to remove pub const QPushButton = opaque {
pub const is_qwidget = true;
// rest of methods, etc
};
pub fn New5(text: []const u8, parent: anytype) QPushButton {
_ = @TypeOf(parent).Pointer.child.is_qwidget; // verify the magic field exists
// ...
}Or you could even generalize it something like |
2 replies
|
One other impediment is that this breaks the ability to pass null parameter types (where valid) as direct parameters. This is survivable but with more verbose parameter syntax. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
While support for dot-call syntax is being explored, the resulting parameter type ambiguity remains. Take the abbreviated
helloworldexample after the dot-call syntax is applied:In this structure, the function definition for
QPushButton.New5becomes:This structure requires call site syntax for each polymorphic parameter (
.ptr) and still affords no safety if an improper parameter type is passed, leading to the potential for runtime crashes or undefined behavior.The question becomes, "what if this syntax could be safer and offer a simpler interface?"
If adopted, the proposal would change the call site syntax to:
The function definition would become:
The comptime validation would be backed by generated functions and correlating StaticStringMaps:
Zig zen favors the comptime approach:
All reactions