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

improve compile error when using comptime concatenation and operand has runtime known length #11773

Closed
nektro opened this issue Jun 1, 2022 · 5 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. error message This issue points out an error message that is unhelpful and should be improved. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@nektro
Copy link
Contributor

nektro commented Jun 1, 2022

Zig Version

0.10.0-dev.2444+83beed09e

Steps to Reproduce

const std = @import("std");

test {
    const a = foo() ++ "bb";
    try std.testing.expect(a.len == 5);
}

fn foo() []const u8 {
    return "aaa";
}

Expected Behavior

All 1 tests passed.

Actual Behavior

test.zig:4:18: error: unable to resolve comptime value
    const a = foo() ++ "bb";
                 ^

only affects stage2

@nektro nektro added the bug Observed behavior contradicts documented or intended behavior label Jun 1, 2022
@nektro
Copy link
Contributor Author

nektro commented Jun 1, 2022

moving a to decl scope makes this work, so this only affects consts in block scope

@Vexu
Copy link
Member

Vexu commented Jun 1, 2022

Not a bug, stage2 implements #7147 so the operands aren't implicitly conptime but slice concatenation still requires the length to be known.

@andrewrk andrewrk removed the bug Observed behavior contradicts documented or intended behavior label Jun 1, 2022
@andrewrk andrewrk added this to the 0.10.0 milestone Jun 1, 2022
@andrewrk
Copy link
Member

andrewrk commented Jun 1, 2022

Yep this is working as designed.

@andrewrk andrewrk closed this as not planned Won't fix, can't repro, duplicate, stale Jun 1, 2022
@andrewrk
Copy link
Member

andrewrk commented Jun 1, 2022

Re-opening for a better compile error. It should say something like, "array concatenation operand requires comptime-known length".

@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness. labels Jun 1, 2022
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Jun 1, 2022
@andrewrk andrewrk changed the title stage2: unable to resolve comptime value when using comptime concatenation improve compile error when using comptime concatenation and operand has runtime known length Jun 1, 2022
@andrewrk andrewrk reopened this Jun 1, 2022
@Vexu Vexu added the error message This issue points out an error message that is unhelpful and should be improved. label Jun 1, 2022
@Vexu
Copy link
Member

Vexu commented Oct 28, 2022

Fixed in #12117

a.zig:6:18: error: unable to resolve comptime value
    const a = foo() ++ "bb";
              ~~~^~
a.zig:6:18: note: slice value being concatenated must be comptime-known

@Vexu Vexu closed this as completed Oct 28, 2022
@Vexu Vexu modified the milestones: 0.11.0, 0.10.0 Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. error message This issue points out an error message that is unhelpful and should be improved. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

3 participants