Improve support for extending protocols to primitive arrays

Description

It is possible to extend protocols to primitive arrays but specifying the class for the type is a little tricky:

However, things go bad if you try to do more than one of these:

The code in {parse-impls} is seeing the second {(Class/forName "[I")} as a function, not as a new type. One workaround for this is to only extend the protocol to one type at a time.

It would be even better (moving into enhancement area) if there was a syntax here to specify primitive array types - we already have the syntax of {bytes, ints, longs}, etc for type hints and those seem perfectly good to me.

Environment

None

Activity

Show:
nahuel
September 19, 2014, 12:08 AM

It also breaks when extending only one array type:

But changing the declaration order fixes it:

Alex Miller
January 12, 2016, 9:16 PM

Dupe of

Alex Miller
June 7, 2016, 10:00 PM

On further inspection, I don't think this is a dupe of but merely a related problem.

Greg Chapman
March 18, 2017, 5:04 PM

Using Class/forName has a further problem, as type-hints on the this parameter are longer emitted:

Reflection warnings are also generated for non-primitive arrays (so just supporting ints etc, won't completely fix this problem). It would be good to have a solution which covered all the problems with extending protocols to arrays.

Assignee

Unassigned

Reporter

Alex Miller

Labels

Approval

Vetted

Patch

None

Affects versions

Priority

Major