core.typed

Type Error Cannot invoke type: Keyword with non-literal keywords

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:

Description

Using non-literal keywords for map lookup results in "Type Error Cannot invoke Keyword"

Code to reproduce:

(ns foo
  (:require [clojure.core.typed :as t])
  (:import clojure.lang.Keyword))

(t/ann bar [Keyword -> Number])
(defn bar [k]
  (k {:a 1 :b 2}))

Repl:

clojure-programming.core=> (check-ns 'foo)
Initializing core.typed ...
Loading Clojurescript...
Clojurescript not found
"Elapsed time: 2419.011 msecs"
core.typed initialized.
Start collecting foo
Finished collecting foo
Collected 1 namespaces in 2507.171 msecs
Start checking foo
Checked foo in 64.561 msecs
Type Error (foo:7:3) Cannot invoke type: Keyword
in: (k (quote {:a 1, :b 2}))

ExceptionInfo Type Checker: Found 1 error  clojure.core/ex-info (core.clj:4327)

Activity

Hide
Gordon Syme added a comment -

The 'get' failure was due to me using an incorrect return type (should have been (U nil Number))

Show
Gordon Syme added a comment - The 'get' failure was due to me using an incorrect return type (should have been (U nil Number))
Hide
Gordon Syme added a comment -

(get m k) and (m k) are also erroring out for me:

Code:

(t/ann baz [Keyword -> Number])
(defn baz [k]
  (get {:a 1 :b 2} k))

(t/ann qux [Keyword -> Number])
(defn qux [k]
  ({:a 1 :b 2} k))

Repl:

Type Error (foo:11:3) Polymorphic static method clojure.lang.RT/get could not be applied to arguments:
Polymorphic Variables:
	x
	y

Domains:
	(clojure.lang.IPersistentSet x) Any
	nil Any
	(t/Option (clojure.lang.ILookup Any x)) Any
	java.util.Map Any
	java.lang.String Any
	(clojure.lang.IPersistentSet x) Any y
	nil Any y
	(t/Option (clojure.lang.ILookup Any x)) Any y
	java.util.Map Any y
	java.lang.String Any y

Arguments:
	(HMap :mandatory {:b (Value 2), :a (Value 1)} :complete? true) clojure.lang.Keyword

Ranges:
	(t/Option x)
	nil
	(t/Option x)
	(t/Option Any)
	(t/Option java.lang.Character)
	(U y x)
	y
	(U y x)
	Any
	(U y java.lang.Character)

with expected type:
	java.lang.Number

in: (clojure.lang.RT/get (quote {:a 1, :b 2}) k)
in: (clojure.lang.RT/get (quote {:a 1, :b 2}) k)


Type Error (foo:15:3) Cannot invoke type: (HMap :mandatory {:b (Value 2), :a (Value 1)} :complete? true)
in: ((quote {:a 1, :b 2}) k)
Show
Gordon Syme added a comment - (get m k) and (m k) are also erroring out for me: Code:
(t/ann baz [Keyword -> Number])
(defn baz [k]
  (get {:a 1 :b 2} k))

(t/ann qux [Keyword -> Number])
(defn qux [k]
  ({:a 1 :b 2} k))
Repl:
Type Error (foo:11:3) Polymorphic static method clojure.lang.RT/get could not be applied to arguments:
Polymorphic Variables:
	x
	y

Domains:
	(clojure.lang.IPersistentSet x) Any
	nil Any
	(t/Option (clojure.lang.ILookup Any x)) Any
	java.util.Map Any
	java.lang.String Any
	(clojure.lang.IPersistentSet x) Any y
	nil Any y
	(t/Option (clojure.lang.ILookup Any x)) Any y
	java.util.Map Any y
	java.lang.String Any y

Arguments:
	(HMap :mandatory {:b (Value 2), :a (Value 1)} :complete? true) clojure.lang.Keyword

Ranges:
	(t/Option x)
	nil
	(t/Option x)
	(t/Option Any)
	(t/Option java.lang.Character)
	(U y x)
	y
	(U y x)
	Any
	(U y java.lang.Character)

with expected type:
	java.lang.Number

in: (clojure.lang.RT/get (quote {:a 1, :b 2}) k)
in: (clojure.lang.RT/get (quote {:a 1, :b 2}) k)


Type Error (foo:15:3) Cannot invoke type: (HMap :mandatory {:b (Value 2), :a (Value 1)} :complete? true)
in: ((quote {:a 1, :b 2}) k)

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: