Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to return a pointer in an Union #269

Open
krichprollsch opened this issue Jan 22, 2025 · 0 comments
Open

Impossible to return a pointer in an Union #269

krichprollsch opened this issue Jan 22, 2025 · 0 comments

Comments

@krichprollsch
Copy link
Member

I would like be able to return a pointer to an object via the Union.

Example with html/Window from https://github.com/lightpanda-io/browser, the following Union declaration:

const generate = @import("../generate.zig");                                     
pub const Interfaces = generate.Tuple(.{                                         
    Window,                                                                      
});                                                                              
const Generated = generate.Union.compile(Interfaces);                            
pub const Union = Generated._union;                                              
pub const Tags = Generated._enum; 

Adding this function doesn't compile.

    pub fn get_window(self: *Window) Union {                                     
        return .{ .Window = self };                                            
    }  
$ zig build
install
└─ install lightpanda
   └─ zig build-exe lightpanda Debug native 1 errors
src/html/window.zig:81:29: error: expected type 'html.window.Window', found '*html.window.Window'
        return .{ .Window = self };
                            ^~~~
src/html/window.zig:43:20: note: struct declared here
pub const Window = struct {
                   ^~~~~~
referenced by:
    callFunc__anon_29998: vendor/zig-js-runtime/src/engines/v8/generate.zig:916:22
    getter: vendor/zig-js-runtime/src/engines/v8/generate.zig:1029:21
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

But this one works.

    pub fn get_window(self: *Window) Union {                                     
        return .{ .Window = self.* };                                            
    }  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant