<< Back to previous view

[CTYP-77] Type Error Cannot invoke type: Keyword with non-literal keywords Created: 02/Oct/13  Updated: 09/Oct/13  Resolved: 09/Oct/13

Status: Closed
Project: core.typed
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Gordon Syme Assignee: Ambrose Bonnaire-Sergeant
Resolution: Completed Votes: 0
Labels: None
Environment:

project.clj:

(defproject clojure-programming "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.5.1"]
[org.clojure/core.typed "0.2.13"]]
:main clojure-programming.core)



 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)


 Comments   
Comment by Gordon Syme [ 02/Oct/13 5:38 AM ]

(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)
Comment by Gordon Syme [ 02/Oct/13 7:27 AM ]

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

Comment by Ambrose Bonnaire-Sergeant [ 09/Oct/13 8:06 PM ]

Fixed https://github.com/clojure/core.typed/commit/46ac96ce7b42fc2191710e057716e03508c8d0e5

Generated at Sat Aug 23 13:56:20 CDT 2014 using JIRA 4.4#649-r158309.