Replies: 3 comments 2 replies
-
|
Due to how the type system is currently projected, the comptime checking approach is brittle, leading to false negatives: |
Beta Was this translation helpful? Give feedback.
-
|
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 |
Beta Was this translation helpful? Give feedback.
-
|
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. |
Beta Was this translation helpful? Give feedback.
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:
Beta Was this translation helpful? Give feedback.
All reactions