eval: Improve ExprConcatStrings error messages and positions
"while evaluating a path segment" was just plain wrong Co-authored-by: eldritch horrors <pennae@lix.systems> Change-Id: I827374635df2887d17a8ee8b1755c078bf0b506b
This commit is contained in:
co-authored by
eldritch horrors
parent
7017def185
commit
8782c7533f
@@ -434,7 +434,7 @@ Value ExprConcatStrings::eval(EvalState & state, Env & env)
|
||||
} else {
|
||||
state.ctx.errors
|
||||
.make<EvalError>("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<EvalError>("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<EvalError>("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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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|
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
error:
|
||||
… while evaluating a path segment
|
||||
… while evaluating a string interpolation
|
||||
at /pwd/in.nix:1:2:
|
||||
1| "${x: x}"
|
||||
| ^
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
error:
|
||||
… while evaluating a path segment
|
||||
… while evaluating a string interpolation
|
||||
at /pwd/in.nix:1:3:
|
||||
1| ''${x: x}''
|
||||
| ^
|
||||
|
||||
@@ -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}''
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
error:
|
||||
… while evaluating a path segment
|
||||
… while evaluating a string interpolation
|
||||
at /pwd/in.nix:1:2:
|
||||
1| "${42}" == "42"
|
||||
| ^
|
||||
|
||||
Reference in New Issue
Block a user