core.typed

ann-form requires fully qualified classnames

Details

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

Description

Classes imported into a namespace are visible to clojure.core.type/ann without qualification, but require full qualification with 'clojure.core.type/ann-form.

For example:

(ns ring.typed.util.data
  "Miscellaneous functions for manipulating data structures."
  (:require [clojure.core.typed :refer [ann ann-form]])

  (:import (clojure.lang IPersistentVector
                         IPersistentMap)))

(ann assoc-conj
     (All [x] (Fn [(IPersistentMap Any (U x (IPersistentVector (U Any x)))) Any x -> 
                   (IPersistentMap Any (U x (IPersistentVector x)))]
                  [(IPersistentVector (U x (IPersistentVector x))) Integer x ->
                   (IPersistentVector (U x (IPersistentVector x)))])))
(defn assoc-conj
  "Associate a key with a value in a map. If the key already exists in the map,
  a vector of values is associated with the key."
  [map key val]
  (assoc map key
    (if-let [cur (get map key)]
      (if (vector? cur)
        (ann-form (conj cur val)
                  (IPersistentVector x))
        [cur val])
      val)))

This results in a "Cannot parse list: (IPersistentVector x)" Exception

When

(ann-form (conj cur val)
                  (IPersistentVector x))

is changed to

(ann-form (conj cur val)
                  (clojure.lang.IPersistentVector x))

checking works.

I have been running check-ns from the 'user namespace

Activity

Andrew Brehaut made changes -
Field Original Value New Value
Description Classes imported into a namespace are visible to clojure.core.type/ann without qualification, but require full qualification with 'clojure.core.type/ann-form.

For example:

{code}
(ns ring.typed.util.data
  "Miscellaneous functions for manipulating data structures."
  (:require [clojure.core.typed :refer [ann ann-form]])

  (:import (clojure.lang IPersistentVector
                         IPersistentMap)))

(ann assoc-conj
     (All [x] (Fn [(IPersistentMap Any (U x (IPersistentVector (U Any x)))) Any x ->
                   (IPersistentMap Any (U x (IPersistentVector x)))]
                  [(IPersistentVector (U x (IPersistentVector x))) Integer x ->
                   (IPersistentVector (U x (IPersistentVector x)))])))
(defn assoc-conj
  "Associate a key with a value in a map. If the key already exists in the map,
  a vector of values is associated with the key."
  [map key val]
  (assoc map key
    (if-let [cur (get map key)]
      (if (vector? cur)
        (ann-form (conj cur val)
                  (IPersistentVector x))
        [cur val])
      val)))
{code}

This results in a "Cannot parse list: (IPersistentVector x)" Exception

When

{code}(ann-form (conj cur val)
                  (IPersistentVector x)){code}

is changed to

{code}(ann-form (conj cur val)
                  (clojure.lang.IPersistentVector x)){code}

checking works.
Classes imported into a namespace are visible to clojure.core.type/ann without qualification, but require full qualification with 'clojure.core.type/ann-form.

For example:

{code}
(ns ring.typed.util.data
  "Miscellaneous functions for manipulating data structures."
  (:require [clojure.core.typed :refer [ann ann-form]])

  (:import (clojure.lang IPersistentVector
                         IPersistentMap)))

(ann assoc-conj
     (All [x] (Fn [(IPersistentMap Any (U x (IPersistentVector (U Any x)))) Any x ->
                   (IPersistentMap Any (U x (IPersistentVector x)))]
                  [(IPersistentVector (U x (IPersistentVector x))) Integer x ->
                   (IPersistentVector (U x (IPersistentVector x)))])))
(defn assoc-conj
  "Associate a key with a value in a map. If the key already exists in the map,
  a vector of values is associated with the key."
  [map key val]
  (assoc map key
    (if-let [cur (get map key)]
      (if (vector? cur)
        (ann-form (conj cur val)
                  (IPersistentVector x))
        [cur val])
      val)))
{code}

This results in a "Cannot parse list: (IPersistentVector x)" Exception

When

{code}(ann-form (conj cur val)
                  (IPersistentVector x)){code}

is changed to

{code}(ann-form (conj cur val)
                  (clojure.lang.IPersistentVector x)){code}

checking works.


I have been running check-ns from the 'user namespace
Hide
Ambrose Bonnaire-Sergeant added a comment -

Confirmed. This is due to running the type checker in a namespace other than the namespace being checked.

Show
Ambrose Bonnaire-Sergeant added a comment - Confirmed. This is due to running the type checker in a namespace other than the namespace being checked.
Ambrose Bonnaire-Sergeant made changes -
Priority Minor [ 4 ] Major [ 3 ]
Ambrose Bonnaire-Sergeant made changes -
Fix Version/s 0.2.0 [ 10158 ]
Ambrose Bonnaire-Sergeant made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Ambrose Bonnaire-Sergeant made changes -
Status Resolved [ 5 ] Closed [ 6 ]

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: