Skip to content

Peer type resolution of pointers to arrays should give slices #6833

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

Closed
daurnimator opened this issue Oct 27, 2020 · 1 comment
Closed

Peer type resolution of pointers to arrays should give slices #6833

daurnimator opened this issue Oct 27, 2020 · 1 comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.

Comments

@daurnimator
Copy link
Contributor

if (some_cond) "foo" else "something else"

Currently fails with

error: expected type '*const [3:0]u8', found '*const [14:0]u8'

I propose that peer type resolution in situations like this instead results in a [:0]const u8

I also propose that various pointer attributes would have different behaviour:

  • align -> result type should have lowest common denominator of alignment of operands
  • const -> if either type is const, resulting slice is const
@daurnimator daurnimator added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Oct 27, 2020
@Vexu Vexu added this to the 0.8.0 milestone Oct 27, 2020
@daurnimator
Copy link
Contributor Author

Nevermind, this is already the case; my test snippet was just running into #3882

const std = @import("std");

pub fn main() void {
  var b = true;
  var f = if (b) "foo" else "something else";
  std.debug.print("{}:{}\n", .{@typeName(@TypeOf(f)), f});
}

@Vexu Vexu modified the milestones: 0.8.0, 0.7.0 Oct 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

2 participants