Skip to content

Commit 64afff8

Browse files
committed
Rework the int-checking to use proper type-tainting rather than just checking at the very end. Per WG discussion, this lets us type-check for integer even when we allow things like attr(foo integer) that aren't known at parse-time.
--HG-- extra : rebase_source : 36e3ec24b70ed433dfcc24dd674ce10d06af075e
1 parent cd4aa8a commit 64afff8

2 files changed

Lines changed: 42 additions & 28 deletions

File tree

css3-values/Overview.html

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,17 +1482,26 @@ <h4 id=calc-type-checking><span class=secno>8.1.2. </span> Type Checking</h4>
14821482
operators for simplicity):
14831483

14841484
<ul>
1485-
<li>At ‘<code class=css>,</code>’, ‘<code class=css>+</code>’, or
1486-
<code class=css>-</code>’, check that both sides have the same type;
1487-
resolve to that type.
1488-
1489-
<li>At ‘<code class=css>*</code>’, check that at least one side is <a
1490-
href="#number-value"><var>&lt;number></var></a>; resolve to the type of
1491-
the other side
1492-
1493-
<li>At ‘<code class=css>/</code>’, check that the right side is <a
1494-
href="#number-value"><var>&lt;number></var></a>; resolve to the type of
1495-
the left side.
1485+
<li> At ‘<code class=css>,</code>’, ‘<code class=css>+</code>’, or
1486+
<code class=css>-</code>’, check that both sides have the same type,
1487+
or that one side is a <a href="#number-value"><var>&lt;number></var></a>
1488+
and the other is an <a href="#integer-value"><var>&lt;integer></var></a>.
1489+
If both sides are the same type, resolve to that type. If one side is a
1490+
<a href="#number-value"><var>&lt;number></var></a> and the other is an <a
1491+
href="#integer-value"><var>&lt;integer></var></a>, resolve to <a
1492+
href="#number-value"><var>&lt;number></var></a>.
1493+
1494+
<li> At ‘<code class=css>*</code>’, check that at least one side is <a
1495+
href="#number-value"><var>&lt;number></var></a>. If both sides are <a
1496+
href="#integer-value"><var>&lt;integer></var></a>, resolve to <a
1497+
href="#integer-value"><var>&lt;integer></var></a>. Otherwise, resolve to
1498+
the type of the other side.
1499+
1500+
<li> At ‘<code class=css>/</code>’, check that the right side is <a
1501+
href="#number-value"><var>&lt;number></var></a>. If the left side is <a
1502+
href="#integer-value"><var>&lt;integer></var></a>, resolve to <a
1503+
href="#number-value"><var>&lt;number></var></a>. Otherwise, resolve to
1504+
the type of the left side.
14961505
</ul>
14971506

14981507
<p>If an operator does not pass the above checks, the expression is
@@ -1501,11 +1510,6 @@ <h4 id=calc-type-checking><span class=secno>8.1.2. </span> Type Checking</h4>
15011510
to zero (as purely-numeric expressions can be evaluated without any
15021511
additional information at parse time).
15031512

1504-
<p> If the type of the result, after resolving all subexpressions, is an
1505-
integral <a href="#number-value"><var>&lt;number></var></a>, the
1506-
calc()&apos;s resolved type is <a
1507-
href="#integer-value"><var>&lt;integer></var></a>.
1508-
15091513
<h4 id=calc-range><span class=secno>8.1.3. </span> Range Checking</h4>
15101514

15111515
<p>The value resulting from an expression must be clamped to the range

css3-values/Overview.src.html

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,14 +1037,30 @@ <h4 id='calc-type-checking'>
10371037
the operators for simplicity):
10381038

10391039
<ul>
1040-
<li>At '','', ''+'', or ''-'', check that both sides have the same type;
1041-
resolve to that type.</li>
1040+
<li>
1041+
At '','', ''+'', or ''-'',
1042+
check that both sides have the same type,
1043+
or that one side is a <var>&lt;number></var> and the other is an <var>&lt;integer></var>.
1044+
If both sides are the same type,
1045+
resolve to that type.
1046+
If one side is a <var>&lt;number></var> and the other is an <var>&lt;integer></var>,
1047+
resolve to <var>&lt;number></var>.
10421048

1043-
<li>At ''*'', check that at least one side is <var>&lt;number></var>;
1044-
resolve to the type of the other side</li>
1049+
<li>
1050+
At ''*'',
1051+
check that at least one side is <var>&lt;number></var>.
1052+
If both sides are <var>&lt;integer></var>,
1053+
resolve to <var>&lt;integer></var>.
1054+
Otherwise,
1055+
resolve to the type of the other side.
10451056

1046-
<li>At ''/'', check that the right side is <var>&lt;number></var>;
1047-
resolve to the type of the left side.</li>
1057+
<li>
1058+
At ''/'',
1059+
check that the right side is <var>&lt;number></var>.
1060+
If the left side is <var>&lt;integer></var>,
1061+
resolve to <var>&lt;number></var>.
1062+
Otherwise,
1063+
resolve to the type of the left side.
10481064
</ul>
10491065

10501066
<p>If an operator does not pass the above checks, the expression is invalid.
@@ -1053,12 +1069,6 @@ <h4 id='calc-type-checking'>
10531069
(as purely-numeric expressions can be evaluated without any additional
10541070
information at parse time).</p>
10551071

1056-
<p>
1057-
If the type of the result,
1058-
after resolving all subexpressions,
1059-
is an integral <var>&lt;number></var>,
1060-
the calc()&apos;s resolved type is <var>&lt;integer></var>.
1061-
10621072
<h4 id='calc-range'>
10631073
Range Checking</h4>
10641074

0 commit comments

Comments
 (0)