Skip to content

Commit 5451cee

Browse files
committed
CLJ-2680 Primitive local bindings can have matching type hint
Signed-off-by: Alex Miller <alex.miller@cognitect.com>
1 parent e45e478 commit 5451cee

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/jvm/clojure/lang/Compiler.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6024,9 +6024,14 @@ public static class LocalBindingExpr implements Expr, MaybePrimitiveExpr, Assign
60246024
public LocalBindingExpr(LocalBinding b, Symbol tag)
60256025
{
60266026
if(b.getPrimitiveType() != null && tag != null)
6027-
throw new UnsupportedOperationException("Can't type hint a primitive local");
6027+
if(! b.getPrimitiveType().equals(tagClass(tag)))
6028+
throw new UnsupportedOperationException("Can't type hint a primitive local with a different type");
6029+
else
6030+
this.tag = null;
6031+
else
6032+
this.tag = tag;
6033+
60286034
this.b = b;
6029-
this.tag = tag;
60306035

60316036
this.clearPath = (PathNode)CLEAR_PATH.get();
60326037
this.clearRoot = (PathNode)CLEAR_ROOT.get();

test/clojure/test_clojure/numbers.clj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@
184184
(catch RuntimeException e :error)))]
185185
(is (= vals (map wrapped inputs)))))))
186186

187+
(deftest test-prim-with-matching-hint
188+
(is (= 1 (let [x 1.2] (Math/round ^double x)))))
189+
187190
;; *** Functions ***
188191

189192
(defonce DELTA 1e-12)

0 commit comments

Comments
 (0)