Skip to content

Cannot assoc record fields with special characters in their name. #1029

Closed
@mitch-kyle

Description

When record field names contain special characters it's not possible to assoc them:

user> (defrecord A [?])
<class 'user.A'>

user> (assoc (->A nil) :? 1)

;; Expected
#user.A{:? 1}

;; Actual 
;; raises TypeError: A.__init__() got an unexpected keyword argument '?'

Part of this is just a missed call to munge in the assoc method of the defrecord macro but there's another problem where it looks like the compiler is generating different key names based on the position of the special characters: I'm not sure if we just want to code around these cases or actually change how they are generated.

user> (import inspect)
<module 'inspect' from '/usr/lib/python3.12/inspect.py'>

user> (defrecord A [?])
<class 'user.A'>
user> (inspect/signature (.-__init__ A))
<Signature (self, Q__, meta=None, recmap={}) -> None>

user> (defrecord A [x?])
<class 'user.A'>
user> (inspect/signature (.-__init__ A))
<Signature (self, x__Q__, meta=None, recmap={}) -> None>

user> (defrecord A [?x])
<class 'user.A'>
user> (inspect/signature (.-__init__ A))
<Signature (self, A__Q__x, meta=None, recmap={}) -> None>

user> (defrecord A [??])
<class 'user.A'>
user> (inspect/signature (.-__init__ A))
<Signature (self, Q____Q__, meta=None, recmap={}) -> None>

user> (defrecord A [?x?])
<class 'user.A'>
user> (inspect/signature (.-__init__ A))
<Signature (self, Q__x__Q__, meta=None, recmap={}) -> None>

user> (defrecord A [??x])
<class 'user.A'>
user> (inspect/signature (.-__init__ A))
<Signature (self, A__Q____Q__x, meta=None, recmap={}) -> None>

user> (defrecord A [?x-])
<class 'user.A'>
user> (inspect/signature (.-__init__ A))
<Signature (self, A__Q__x_, meta=None, recmap={}) -> None>

(defrecord A [x?x])
<class 'user.A'>
user> (inspect/signature (.-__init__ A))
<Signature (self, x__Q__x, meta=None, recmap={}) -> None>
Unmunged Munged
? Q__
x? x__Q__
?x A__Q__x It's not clear to me why the class name is added here.
?? Q____Q__
?x? Q__x__Q__
??x A__Q____Q__x
?x- A__Q__x_
x?x x__Q__x

Metadata

Assignees

No one assigned

    Labels

    issue-type:bugSomething isn't workinglangIssue pertaining to Basilisp language modules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions