diff --git a/lix/libexpr/eval-expr.cc b/lix/libexpr/eval-expr.cc index 01c057479..6cd7a014d 100644 --- a/lix/libexpr/eval-expr.cc +++ b/lix/libexpr/eval-expr.cc @@ -434,7 +434,7 @@ Value ExprConcatStrings::eval(EvalState & state, Env & env) } else { state.ctx.errors .make("integer overflow in adding %1% + %2%", n, vTmp.integer()) - .atPos(i_pos) + .atPos(isInterpolation ? i_pos : pos) .debugThrow(); } } else if (vTmp.type() == nFloat) { @@ -444,7 +444,7 @@ Value ExprConcatStrings::eval(EvalState & state, Env & env) nf += vTmp.fpoint(); } else { state.ctx.errors.make("cannot add %1% to an integer", showType(vTmp)) - .atPos(i_pos) + .atPos(isInterpolation ? i_pos : pos) .withFrame(env, *this) .debugThrow(); } @@ -455,7 +455,7 @@ Value ExprConcatStrings::eval(EvalState & state, Env & env) nf += vTmp.fpoint(); } else { state.ctx.errors.make("cannot add %1% to a float", showType(vTmp)) - .atPos(i_pos) + .atPos(isInterpolation ? i_pos : pos) .withFrame(env, *this) .debugThrow(); } @@ -471,13 +471,18 @@ Value ExprConcatStrings::eval(EvalState & state, Env & env) : StringCoercionMode::Strict; /* skip canonization of first path, which would only be not - canonized in the first place if it's coming from a ./${foo} type - path */ + canonized in the first place if it's coming from a ./${foo} type + path */ auto part = state.coerceToString( - i_pos, + isInterpolation ? i_pos : pos, vTmp, context, - "while evaluating a path segment", + (isInterpolation && firstType == nPath) + ? "while evaluating a path interpolation" + : (isInterpolation ? "while evaluating a string interpolation" + // TODO: to the person who eventually cleans up all of this mess, + // please turn this into "cannot concatenate $type to a $type" instead. + : "while concatenating"), coercionMode, firstType == nString, !first diff --git a/tests/functional/repl_characterization/data/basic_repl.test b/tests/functional/repl_characterization/data/basic_repl.test index 5c7245cbb..acc6d89f9 100644 --- a/tests/functional/repl_characterization/data/basic_repl.test +++ b/tests/functional/repl_characterization/data/basic_repl.test @@ -13,10 +13,10 @@ Expect the trace to not contain any traceback: nix-repl> f 2 error: - … while evaluating a path segment - at «string»:1:13: + … while concatenating + at «string»:1:11: 1| f = a: "" + a - | ^ + | ^ error: cannot coerce an integer to a string: 2 @@ -37,10 +37,10 @@ Expect the trace to have traceback: 1| f = a: "" + a | ^ - … while evaluating a path segment - at «string»:1:13: + … while concatenating + at «string»:1:11: 1| f = a: "" + a - | ^ + | ^ error: cannot coerce an integer to a string: 2 @@ -51,9 +51,9 @@ Turning it off should also work: nix-repl> f 2 error: - … while evaluating a path segment - at «string»:1:13: + … while concatenating + at «string»:1:11: 1| f = a: "" + a - | ^ + | ^ error: cannot coerce an integer to a string: 2 diff --git a/tests/functional2/lang/arithmetic/eval-fail-overflowing-add.err.exp b/tests/functional2/lang/arithmetic/eval-fail-overflowing-add.err.exp index e4c57f3dc..8d81c34dd 100644 --- a/tests/functional2/lang/arithmetic/eval-fail-overflowing-add.err.exp +++ b/tests/functional2/lang/arithmetic/eval-fail-overflowing-add.err.exp @@ -1,6 +1,6 @@ error: integer overflow in adding 9223372036854775807 + 1 - at /pwd/in.nix:4:8: + at /pwd/in.nix:4:6: 3| b = 1; 4| in a + b - | ^ + | ^ 5| diff --git a/tests/functional2/lang/bad_string_interpolation/eval-fail-1.err.exp b/tests/functional2/lang/bad_string_interpolation/eval-fail-1.err.exp index a9728e8bb..10262a964 100644 --- a/tests/functional2/lang/bad_string_interpolation/eval-fail-1.err.exp +++ b/tests/functional2/lang/bad_string_interpolation/eval-fail-1.err.exp @@ -1,5 +1,5 @@ error: - … while evaluating a path segment + … while evaluating a string interpolation at /pwd/in.nix:1:2: 1| "${x: x}" | ^ diff --git a/tests/functional2/lang/bad_string_interpolation/eval-fail-3.err.exp b/tests/functional2/lang/bad_string_interpolation/eval-fail-3.err.exp index 3a1e06e2e..d600db739 100644 --- a/tests/functional2/lang/bad_string_interpolation/eval-fail-3.err.exp +++ b/tests/functional2/lang/bad_string_interpolation/eval-fail-3.err.exp @@ -1,5 +1,5 @@ error: - … while evaluating a path segment + … while evaluating a string interpolation at /pwd/in.nix:1:3: 1| ''${x: x}'' | ^ diff --git a/tests/functional2/lang/bad_string_interpolation/eval-fail-4.err.exp b/tests/functional2/lang/bad_string_interpolation/eval-fail-4.err.exp index 555bc7e70..e08c805b6 100644 --- a/tests/functional2/lang/bad_string_interpolation/eval-fail-4.err.exp +++ b/tests/functional2/lang/bad_string_interpolation/eval-fail-4.err.exp @@ -1,5 +1,5 @@ error: - … while evaluating a path segment + … while evaluating a string interpolation at /pwd/in.nix:9:3: 8| # The error message should not be too long. 9| ''${pkgs}'' diff --git a/tests/functional2/lang/string-coerce-integers/eval-fail-accidental-coerce.err.exp b/tests/functional2/lang/string-coerce-integers/eval-fail-accidental-coerce.err.exp index b9b72507e..1b34c869a 100644 --- a/tests/functional2/lang/string-coerce-integers/eval-fail-accidental-coerce.err.exp +++ b/tests/functional2/lang/string-coerce-integers/eval-fail-accidental-coerce.err.exp @@ -5,10 +5,10 @@ error: | ^ 2| - … while evaluating a path segment - at /pwd/in.nix:1:14: + … while concatenating + at /pwd/in.nix:1:12: 1| let x = "" + 42; in x == "42" - | ^ + | ^ 2| error: cannot coerce an integer to a string: 42 diff --git a/tests/functional2/lang/string-coerce-integers/no-xp.err.exp b/tests/functional2/lang/string-coerce-integers/no-xp.err.exp index 95b7a9d91..f507575c1 100644 --- a/tests/functional2/lang/string-coerce-integers/no-xp.err.exp +++ b/tests/functional2/lang/string-coerce-integers/no-xp.err.exp @@ -1,5 +1,5 @@ error: - … while evaluating a path segment + … while evaluating a string interpolation at /pwd/in.nix:1:2: 1| "${42}" == "42" | ^