assoc, update-in &c have record-hostile types

Description

(use 'clojure.core.typed)
nil
user=> (ann-record X [x :- Number])
nil
user=> (defrecord X [x])
user.X
user=> (cf (assoc (X. 3) :x 3) X)

0.2.7 thought this should be (Map Any Any)
0.2.9 just thinks you can't do it at all

but it should pass.

Environment

None

Activity

Show:
Chris Spencer
September 22, 2013, 4:59 PM

Had a quick look

So looks like result of (X. 3) is being instantiated as an RClass rather than a DataType?

Chris Spencer
September 22, 2013, 5:12 PM

Found issue:

ann-record doesn't collect so need to wrap in a cf, just awkward

Ambrose Bonnaire-Sergeant
September 23, 2013, 4:07 AM

Global annotations are only collected during type checking.

I've tried to document this, but it seems to frequently trip people up. I've tried to ensure error messages based on missing annotations emphasise annotations must be provided via cf.

eg. https://github.com/clojure/core.typed/wiki/Quick-Guide#type-checking-is-separate-to-compilation-and-must-be-explicitly-run

FWIW this might change in the future to defonce semantics.

There are a couple of other issues here.

1. The Java constructor X. type checked because datatype constructors are normal Java constructors that take Object. ann-record overrides constructors to take the field types.

A couple of approaches to fixing this:

  • warn if constructing an IType or IRecord that is unannotated

  • recommend avoiding the Java constructor in favour of the positional factory.

2. update-in is NYI, ticket here http://dev.clojure.org/jira/browse/CTYP-8

3. assoc might be too strict now. X implements IPersistentMap, so it should be able to assoc anything even if it is unannotated.

(cf (assoc (X. 3) :x 3)) should return (IPersistentMap Any Any).

import
September 24, 2013, 8:58 PM

Comment made by: julian

OK, assoc seems to be behaving itself under 0.2.11.

I should point out I'm using lein typed most of the time, so I'm not that familiar with the repl. I should probably confine myself to submitting scripts that lein typed can run...

This passed, and I think should pass:

(ann-record X [x :- Number])
(defrecord X [x])
(ann Z [-> X])
(defn Z [] (assoc (X. 3) :x 3))

Ambrose Bonnaire-Sergeant
September 25, 2013, 9:13 AM

Ok. Also it would be helpful to include the actual type error or stacktrace in issues.

Completed

Assignee

Ambrose Bonnaire-Sergeant

Reporter

import

Labels

None

Approval

None

Patch

None

Affects versions

Priority

Major
Configure