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

stage3: optional slice to optional multi-item pointer coercion no longer works #12523

Open
jcmoyer opened this issue Aug 20, 2022 · 3 comments
Open
Labels
frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@jcmoyer
Copy link
Contributor

jcmoyer commented Aug 20, 2022

Zig Version

0.10.0-dev.3659+e5e6eb983

Steps to Reproduce

This may be an intended change, but I didn't see it mentioned in the upgrade guide. This used to compile:

const std = @import("std");

fn bar(s: ?[*:0]const u8) void {
    _ = s;
}

fn foo(s: ?[:0]const u8) void {
    bar(s orelse null);
}

pub fn main() !void {
    foo("hello");
}

Expected Behavior

It compiles.

Actual Behavior

It doesn't compile:

D:\Scratch\testfn\src\main.zig:8:11: error: expected type '?[*:0]const u8', found '?[:0]const u8'
    bar(s orelse null);
        ~~^~~~~~~~~~~
D:\Scratch\testfn\src\main.zig:8:11: note: optional type child '[:0]const u8' cannot cast into optional type child '[*:0]const u8'
@jcmoyer jcmoyer added the bug Observed behavior contradicts documented or intended behavior label Aug 20, 2022
@jcmoyer
Copy link
Contributor Author

jcmoyer commented Aug 20, 2022

Sorry original code snippet did not actually reproduce the problem, I've updated it with one that does.

@nektro
Copy link
Contributor

nektro commented Aug 20, 2022

this also highlights a current nastyness when using optionals because ideally you could use something like Optional chaining and do s?.ptr

@Vexu Vexu added frontend Tokenization, parsing, AstGen, Sema, and Liveness. and removed bug Observed behavior contradicts documented or intended behavior labels Aug 21, 2022
@Vexu Vexu added this to the 0.10.0 milestone Aug 21, 2022
@andrewrk andrewrk modified the milestones: 0.10.0, 0.10.1 Aug 23, 2022
@iacore
Copy link
Contributor

iacore commented Dec 12, 2022

The type checker is right (I think).
Fix:
bar(if (s) |ss| ss.ptr else null);

@andrewrk andrewrk modified the milestones: 0.10.1, 0.11.0 Jan 10, 2023
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

5 participants