core.typed

Support clojure.core/cast

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  1. ann-cast.diff
    13/Mar/14 6:23 AM
    1 kB
    Di Xu
  2. ann-cast-v2.diff
    13/Mar/14 8:23 AM
    2 kB
    Di Xu
  3. ann-cast-v3.diff
    14/Mar/14 2:10 AM
    3 kB
    Di Xu
  4. ann-cast-v4.diff
    14/Mar/14 5:43 AM
    3 kB
    Di Xu

Activity

Hide
Di Xu added a comment -

got it.

Show
Di Xu added a comment - got it.
Hide
Ambrose Bonnaire-Sergeant added a comment -

Merged.

For future reference, throws-tc-error? can catch int-errors.

Thanks!

Show
Ambrose Bonnaire-Sergeant added a comment - Merged. For future reference, throws-tc-error? can catch int-errors. Thanks!
Hide
Di Xu added a comment -

added

Show
Di Xu added a comment - added
Hide
Ambrose Bonnaire-Sergeant added a comment -

Ah yes.

Show
Ambrose Bonnaire-Sergeant added a comment - Ah yes.
Hide
Di Xu added a comment -

you mean (cast (ann-form Class Class) (class :any))?

Show
Di Xu added a comment - you mean (cast (ann-form Class Class) (class :any))?
Hide
Ambrose Bonnaire-Sergeant added a comment -

To make an intersection, use c/In.

Also need a test for (cast (ann-form Class Class) :any)

Make a failing test like this:

(is (u/top-level-error-thrown?
(cf (fn [] (cast "a" "a"))))

Please add a few failing tests.

Show
Ambrose Bonnaire-Sergeant added a comment - To make an intersection, use c/In. Also need a test for (cast (ann-form Class Class) :any) Make a failing test like this: (is (u/top-level-error-thrown? (cf (fn [] (cast "a" "a")))) Please add a few failing tests.
Hide
Di Xu added a comment -

thanks for the detailed solution. I'm still not very familiar with its internal type

Show
Di Xu added a comment - thanks for the detailed solution. I'm still not very familiar with its internal type
Hide
Ambrose Bonnaire-Sergeant added a comment -

I wonder if `cast` should make an intersection of the original type and the casted type.

(cast String "a") => (I String (Value "a"))

Perhaps that's more useful. Just implement the simple RClass return type for now.

Instead of testing (-> args first :val), you should inspect the type of
(-> (check (first args)) expr-type ret-t c/fully-resolve-type).

If it's a Value type and the :val field is a `class?`, then it's a special case.

Show
Ambrose Bonnaire-Sergeant added a comment - I wonder if `cast` should make an intersection of the original type and the casted type. (cast String "a") => (I String (Value "a")) Perhaps that's more useful. Just implement the simple RClass return type for now. Instead of testing (-> args first :val), you should inspect the type of (-> (check (first args)) expr-type ret-t c/fully-resolve-type). If it's a Value type and the :val field is a `class?`, then it's a special case.
Hide
Ambrose Bonnaire-Sergeant added a comment -

I mean this is still type correct:

(ann foo [Class Any -> Any])
(defn foo [c a]
(cast c a))

Show
Ambrose Bonnaire-Sergeant added a comment - I mean this is still type correct: (ann foo [Class Any -> Any]) (defn foo [c a] (cast c a))
Hide
Di Xu added a comment -

Well, I'm confused, I only aware of the literal class could be the first argument. could you give me some example of nonliteral class argument?

Show
Di Xu added a comment - Well, I'm confused, I only aware of the literal class could be the first argument. could you give me some example of nonliteral class argument?
Hide
Ambrose Bonnaire-Sergeant added a comment -

The invoke-special case should be more lenient.

If the first argument is a literal class, then it can be special cased, otherwise return :default.

Use RClass-of-with-unknown-params like in :instance-of.

Please add some tests in clojure.core.typed.test.core, testing the special case and the normal case.

Show
Ambrose Bonnaire-Sergeant added a comment - The invoke-special case should be more lenient. If the first argument is a literal class, then it can be special cased, otherwise return :default. Use RClass-of-with-unknown-params like in :instance-of. Please add some tests in clojure.core.typed.test.core, testing the special case and the normal case.
Hide
Di Xu added a comment -

annotate cast using add-invoke-special-method

Show
Di Xu added a comment - annotate cast using add-invoke-special-method

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: