Skip to content

defalias doesn't mirror :dynamic and custom metadata #87

@edenworky

Description

@edenworky

Currently, defalias mirrors specific metadata keys individually by name, namely these:

[:doc :no-doc :arglists :private :macro :added :deprecated :inline :tag :redef]

I noticed this when I tried aliasing a dynamic var and got a not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic or change the namewarning. Is this specifically prohibited for some reason I can't think of?

Moreover, this got me thinking that I have my own metadata on my vars with keys that aren't specifically the ones in that hardcoded list on line 646 of encore.cljc, and would thus also not get mirrored over.

The only metadata which (maybe? but not necessarily honestly) should not be mirrored is specifically the location related ones, i.e. :file, :line, :column, and ofc :ns. Of these, :ns has to not be copied over, as that would defeat the purpose. Are there any other metadata keys which should strictly not be copied over?

As to :file :line and :column there is a case to be made for actually copying them over, insofar as that makes it easier to find the actual source code (i.e., a "go to source" IDE function would get straight to the actual definition rather than any aliasing on them). I can see how that might clash with defalias accepting an alias body (??) (why even?) (isn't that just defn with more steps?) but I rarely call defalias with more than one arg. Feels like it might have more than one responsibility there. Plus defaliases might take multiple values on one :line, tho then again so might the clj reader.

In any case, iff this is the extent of the problem (and again please lmk if I'm missing anything here), it seems to me like the problem might be better solved on both ends by filtering out :ns (and likely :file :line :column) as well as any other specifically problematic ones (is :dynamic problematic for this reason? I can see how it might be a footgun but not why it should be impossible) and opting out of those, rather than opting into the hardcoded selected list on L646 of encore.cljc.

Or else at least some hacky lil dynamic var to store that metadata whitelist that I could bind locally around aliasing.

Let me know your thoughts on this, with your go-ahead I'd be glad to put together a PR for either, and thanks for your wonderful libraries <3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions