Fixed
Details
Details
Assignee
Unassigned
UnassignedReporter
Michael Fogus
Michael FogusApproval
Ok
Patch
Code and Test
Priority

Affects versions
Fix versions
Created October 12, 2023 at 6:07 PM
Updated April 30, 2024 at 1:08 PM
Resolved April 30, 2024 at 1:08 PM
Background
Clojure has long supported string encoded array type hints only by using the Java internal class name:
"[Ljava.lang.String;"
- 1D array of strings"[[D"
- 2D array of primitive doublesand so on.
This syntax is verbose (requires fully-qualified class name), prone to error (due to weird syntax) and non-obvious for users, as it requires arcane JVM String patterns.
Problem
There is no symbolic representation for array types, nor one that doesn’t require familiarity with JVM name munging.
Approach
Add support for a symbol comprising the name of the array component type (primitive, full-qualified class, or import aliases accepted) as the symbol namespace and a dimension component of a single digit in the range 1-9 as the symbol name. This symbolic representation should work for both type hinting and as a class value.
Examples:
java.lang.String/1
orString/1
- 1D array of stringsdouble/2
- 2D array of primitive doublesThe component class may be fully qualified or short-form. In the latter case, the class alias is resolved at compilation time.
Mechanically, the symbolic array type hint will expand into the string encoded form in the compiler to leverage the existing class resolution logic. In syntax quote contexts, the array component class symbol will expand into its package qualified form if resolvable to a class.
The existing support for internal class name strings and special primitive array symbols (like
doubles
) will not be removed, but the new array type symbols should now be the primary one as this works in both value and type hint position.Alternative prior approach
Originally, we solved this problem by recognizing array type symbols with trailing stars corresponding to the dimensionality. However, unlike Clojure namespaces, the JVM classpath space is not arbitrated, therefore adding
*
suffixes to symbols operates in an open environment and clashed with existing JVM class names (such as those generated duringdeftype
definition). This is detailed in https://clojure.atlassian.net/browse/CLJ-2833 .Patch: clj-2807-15.patch (requires revert of clj-2807-9.patch from master first - commit= b2a91435)
Screened by: Alex Miller