Skip to content

Commit

Permalink
Improve error reporting for incompatible units
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Dec 29, 2020
1 parent 2731f36 commit 91b9cb3
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 58 deletions.
8 changes: 3 additions & 5 deletions spec/core_functions/math/atan2/arguments.hrx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<===>
================================================================================
<===> named_args/input.scss
@use "sass:math" as math;
a {b: math.atan2($y: 1, $x: -1)}
Expand Down Expand Up @@ -55,7 +53,7 @@ Error: $x: "0" is not a number.
a {b: math.atan2(1px, 1deg)}

<===> error/incompatible_units/error
Error: Incompatible units deg and px.
Error: $x: 1deg and $y: 1px have incompatible units.
,
2 | a {b: math.atan2(1px, 1deg)}
| ^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -69,7 +67,7 @@ Error: Incompatible units deg and px.
a {b: math.atan2(1, 1px)}

<===> error/unitless_y/error
Error: $y is unitless but $x has unit px. Arguments must all have units or all be unitless.
Error: $x: 1px and $y: 1 have incompatible units (one has units and the other doesn't).
,
2 | a {b: math.atan2(1, 1px)}
| ^^^^^^^^^^^^^^^^^^
Expand All @@ -83,7 +81,7 @@ Error: $y is unitless but $x has unit px. Arguments must all have units or all b
a {b: math.atan2(1px, 1)}

<===> error/unitless_x/error
Error: $y has unit px but $x is unitless. Arguments must all have units or all be unitless.
Error: $x: 1 and $y: 1px have incompatible units (one has units and the other doesn't).
,
2 | a {b: math.atan2(1px, 1)}
| ^^^^^^^^^^^^^^^^^^
Expand Down
20 changes: 10 additions & 10 deletions spec/core_functions/math/clamp.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Error: $max: "0" is not a number.
a {b: math.clamp(1deg, 1px, 1turn)}

<===> error/incompatible_units/min_and_number/error
Error: Incompatible units px and deg.
Error: $number: 1px and $min: 1deg have incompatible units.
,
2 | a {b: math.clamp(1deg, 1px, 1turn)}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -169,7 +169,7 @@ Error: Incompatible units px and deg.
a {b: math.clamp(1deg, 1turn, 1px)}

<===> error/incompatible_units/min_and_max/error
Error: Incompatible units px and deg.
Error: $max: 1px and $min: 1deg have incompatible units.
,
2 | a {b: math.clamp(1deg, 1turn, 1px)}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -183,7 +183,7 @@ Error: Incompatible units px and deg.
a {b: math.clamp(1turn, 1deg, 1px)}

<===> error/incompatible_units/number_and_max/error
Error: Incompatible units px and turn.
Error: $max: 1px and $min: 1turn have incompatible units.
,
2 | a {b: math.clamp(1turn, 1deg, 1px)}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -197,7 +197,7 @@ Error: Incompatible units px and turn.
a {b: math.clamp(1deg, 1px, 1s)}

<===> error/incompatible_units/all/error
Error: Incompatible units s and deg.
Error: $number: 1px and $min: 1deg have incompatible units.
,
2 | a {b: math.clamp(1deg, 1px, 1s)}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -211,7 +211,7 @@ Error: Incompatible units s and deg.
a {b: math.clamp(0, 1px, 2px)}

<===> error/some_unitless/min/error
Error: $min is unitless but $number has unit px. Arguments must all have units or all be unitless.
Error: $number: 1px and $min: 0 have incompatible units (one has units and the other doesn't).
,
2 | a {b: math.clamp(0, 1px, 2px)}
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -225,7 +225,7 @@ Error: $min is unitless but $number has unit px. Arguments must all have units o
a {b: math.clamp(0px, 1, 2px)}

<===> error/some_unitless/number/error
Error: $min has unit px but $number is unitless. Arguments must all have units or all be unitless.
Error: $number: 1 and $min: 0px have incompatible units (one has units and the other doesn't).
,
2 | a {b: math.clamp(0px, 1, 2px)}
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -239,7 +239,7 @@ Error: $min has unit px but $number is unitless. Arguments must all have units o
a {b: math.clamp(0px, 1px, 2)}

<===> error/some_unitless/max/error
Error: $min has unit px but $max is unitless. Arguments must all have units or all be unitless.
Error: $max: 2 and $min: 0px have incompatible units (one has units and the other doesn't).
,
2 | a {b: math.clamp(0px, 1px, 2)}
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -253,7 +253,7 @@ Error: $min has unit px but $max is unitless. Arguments must all have units or a
a {b: math.clamp(0, 1, 2px)}

<===> error/some_unitless/min_and_number/error
Error: $min is unitless but $max has unit px. Arguments must all have units or all be unitless.
Error: $max: 2px and $min: 0 have incompatible units (one has units and the other doesn't).
,
2 | a {b: math.clamp(0, 1, 2px)}
| ^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -267,7 +267,7 @@ Error: $min is unitless but $max has unit px. Arguments must all have units or a
a {b: math.clamp(0, 1px, 2)}

<===> error/some_unitless/min_and_max/error
Error: $min is unitless but $number has unit px. Arguments must all have units or all be unitless.
Error: $number: 1px and $min: 0 have incompatible units (one has units and the other doesn't).
,
2 | a {b: math.clamp(0, 1px, 2)}
| ^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -281,7 +281,7 @@ Error: $min is unitless but $number has unit px. Arguments must all have units o
a {b: math.clamp(0px, 1, 2)}

<===> error/some_unitless/number_and_max/error
Error: $min has unit px but $number is unitless. Arguments must all have units or all be unitless.
Error: $number: 1 and $min: 0px have incompatible units (one has units and the other doesn't).
,
2 | a {b: math.clamp(0px, 1, 2)}
| ^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion spec/core_functions/math/cos.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Error: $number: "0" is not a number.
a {b: math.cos(1px)}

<===> error/unit/error
Error: $number: Expected 1px to be an angle.
Error: $number: Expected 1px to have an angle unit (deg, grad, rad, turn).
,
2 | a {b: math.cos(1px)}
| ^^^^^^^^^^^^^
Expand Down
20 changes: 10 additions & 10 deletions spec/core_functions/math/hypot.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Error: "0" is not a number.
a {b: math.hypot(1deg, 1px, 1turn)}

<===> error/incompatible_units/first_and_second/error
Error: Incompatible units px and deg.
Error: $numbers[2]: 1px and $numbers[1]: 1deg have incompatible units.
,
2 | a {b: math.hypot(1deg, 1px, 1turn)}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -121,7 +121,7 @@ Error: Incompatible units px and deg.
a {b: math.hypot(1deg, 1turn, 1px)}

<===> error/incompatible_units/first_and_third/error
Error: Incompatible units px and deg.
Error: $numbers[3]: 1px and $numbers[1]: 1deg have incompatible units.
,
2 | a {b: math.hypot(1deg, 1turn, 1px)}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -135,7 +135,7 @@ Error: Incompatible units px and deg.
a {b: math.hypot(1turn, 1deg, 1px)}

<===> error/incompatible_units/second_and_third/error
Error: Incompatible units px and turn.
Error: $numbers[3]: 1px and $numbers[1]: 1turn have incompatible units.
,
2 | a {b: math.hypot(1turn, 1deg, 1px)}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -149,7 +149,7 @@ Error: Incompatible units px and turn.
a {b: math.hypot(1turn, 1px, 1s)}

<===> error/incompatible_units/all/error
Error: Incompatible units px and turn.
Error: $numbers[2]: 1px and $numbers[1]: 1turn have incompatible units.
,
2 | a {b: math.hypot(1turn, 1px, 1s)}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -163,7 +163,7 @@ Error: Incompatible units px and turn.
a {b: math.hypot(0, 1px, 2px)}

<===> error/some_unitless/first/error
Error: Argument 1 is unitless but argument 2 has unit px. Arguments must all have units or all be unitless.
Error: $numbers[2]: 1px and $numbers[1]: 0 have incompatible units (one has units and the other doesn't).
,
2 | a {b: math.hypot(0, 1px, 2px)}
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -177,7 +177,7 @@ Error: Argument 1 is unitless but argument 2 has unit px. Arguments must all hav
a {b: math.hypot(0px, 1, 2px)}

<===> error/some_unitless/second/error
Error: Argument 1 has unit px but argument 2 is unitless. Arguments must all have units or all be unitless.
Error: $numbers[2]: 1 and $numbers[1]: 0px have incompatible units (one has units and the other doesn't).
,
2 | a {b: math.hypot(0px, 1, 2px)}
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -191,7 +191,7 @@ Error: Argument 1 has unit px but argument 2 is unitless. Arguments must all hav
a {b: math.hypot(0px, 1px, 2)}

<===> error/some_unitless/third/error
Error: Argument 1 has unit px but argument 3 is unitless. Arguments must all have units or all be unitless.
Error: $numbers[3]: 2 and $numbers[1]: 0px have incompatible units (one has units and the other doesn't).
,
2 | a {b: math.hypot(0px, 1px, 2)}
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -205,7 +205,7 @@ Error: Argument 1 has unit px but argument 3 is unitless. Arguments must all hav
a {b: math.hypot(0, 1, 2px)}

<===> error/some_unitless/first_and_second/error
Error: Argument 1 is unitless but argument 3 has unit px. Arguments must all have units or all be unitless.
Error: $numbers[3]: 2px and $numbers[1]: 0 have incompatible units (one has units and the other doesn't).
,
2 | a {b: math.hypot(0, 1, 2px)}
| ^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -219,7 +219,7 @@ Error: Argument 1 is unitless but argument 3 has unit px. Arguments must all hav
a {b: math.hypot(0, 1px, 2)}

<===> error/some_unitless/first_and_third/error
Error: Argument 1 is unitless but argument 2 has unit px. Arguments must all have units or all be unitless.
Error: $numbers[2]: 1px and $numbers[1]: 0 have incompatible units (one has units and the other doesn't).
,
2 | a {b: math.hypot(0, 1px, 2)}
| ^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -233,7 +233,7 @@ Error: Argument 1 is unitless but argument 2 has unit px. Arguments must all hav
a {b: math.hypot(0px, 1, 2)}

<===> error/some_unitless/second_and_third/error
Error: Argument 1 has unit px but argument 2 is unitless. Arguments must all have units or all be unitless.
Error: $numbers[2]: 1 and $numbers[1]: 0px have incompatible units (one has units and the other doesn't).
,
2 | a {b: math.hypot(0px, 1, 2)}
| ^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion spec/core_functions/math/max.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ a {b: max($arg, 2s)}


<===> error/incompatible_units/error
Error: Incompatible units s and px.
Error: 2s and 1px have incompatible units.
,
2 | a {b: max($arg, 2s)}
| ^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion spec/core_functions/math/min.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ $arg: 1px;
a {b: min($arg, 2s)}

<===> error/incompatible_units/error
Error: Incompatible units s and px.
Error: 2s and 1px have incompatible units.
,
2 | a {b: min($arg, 2s)}
| ^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion spec/core_functions/math/sin.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Error: $number: "0" is not a number.
a {b: math.sin(1px)}

<===> error/unit/error
Error: $number: Expected 1px to be an angle.
Error: $number: Expected 1px to have an angle unit (deg, grad, rad, turn).
,
2 | a {b: math.sin(1px)}
| ^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion spec/core_functions/math/tan.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Error: $number: "0" is not a number.
a {b: math.tan(1px)}

<===> error/unit/error
Error: $number: Expected 1px to be an angle.
Error: $number: Expected 1px to have an angle unit (deg, grad, rad, turn).
,
2 | a {b: math.tan(1px)}
| ^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion spec/core_functions/meta/load_css/error.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ Error: Expected expression.
a {b: 1px + 1em}

<===> from_other/runtime/error
Error: Incompatible units em and px.
Error: 1em and 1px have incompatible units.
,
1 | a {b: 1px + 1em}
| ^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion spec/directives/forward/error/with.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Error: This variable is available from multiple global modules.
$a: c !default;

<===> invalid_expression/error/error
Error: Incompatible units em and px.
Error: 1em and 1px have incompatible units.
,
1 | @forward "upstream" with ($a: 1px + 1em);
| ^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion spec/directives/use/error/with.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Error: This variable is available from multiple global modules.
$a: c !default;

<===> invalid_expression/error/error
Error: Incompatible units em and px.
Error: 1em and 1px have incompatible units.
,
1 | @use "other" with ($a: 1px + 1em);
| ^^^^^^^^^
Expand Down
12 changes: 6 additions & 6 deletions spec/libsass-closed-issues/issue_1577.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ $foo: 10%; // line 1
$error: $foo + 20px; // line 3

<===> error
Error: Incompatible units: 'px' and '%'.
on line 3 of input.scss
Use --trace for backtrace.

<===> error-dart-sass
Error: Incompatible units px and %.
Error: 20px and 10% have incompatible units.
,
3 | $error: $foo + 20px; // line 3
| ^^^^^^^^^^^
'
input.scss 3:9 root stylesheet

<===> error-libsass
Error: Incompatible units: 'px' and '%'.
on line 3 of input.scss
Use --trace for backtrace.
12 changes: 6 additions & 6 deletions spec/non_conformant/errors/for-incompatible-units-fn.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

foo { bar: test(); }
<===> error
Error: Incompatible units: 'px' and '%'.
on line 2 of input.scss
Use --trace for backtrace.

<===> error-dart-sass
Error: Incompatible units % and px.
Error: Expected 100% to have a length unit (in, cm, pc, mm, q, pt, px).
,
2 | @for $i from 100% through 42px {}
| ^^^^
'
input.scss 2:16 test()
input.scss 5:12 root stylesheet

<===> error-libsass
Error: Incompatible units: 'px' and '%'.
on line 2 of input.scss
Use --trace for backtrace.
7 changes: 1 addition & 6 deletions spec/non_conformant/errors/for-incompatible-units.hrx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
<===> input.scss
@for $i from 100% through 42px {}
<===> error
Error: Incompatible units: 'px' and '%'.
on line 1 of input.scss
Use --trace for backtrace.

<===> error-dart-sass
Error: Incompatible units % and px.
Error: Expected 100% to have a length unit (in, cm, pc, mm, q, pt, px).
,
1 | @for $i from 100% through 42px {}
| ^^^^
Expand Down
9 changes: 2 additions & 7 deletions spec/non_conformant/errors/invalid-operation/sub.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@ test {
err: 2px - 2px*2px;
}
<===> error
Error: Incompatible units: 'px' and ''.
on line 2 of input.scss
Use --trace for backtrace.

<===> error-dart-sass
Error: Incompatible units px*px and px.
Error: 4px*px and 2px have incompatible units.
,
2 | err: 2px - 2px*2px;
2 | err: 2px - 2px*2px;
| ^^^^^^^^^^^^^
'
input.scss 2:8 root stylesheet
Expand Down

0 comments on commit 91b9cb3

Please sign in to comment.