aboutsummaryrefslogtreecommitdiff
path: root/src/lux/type/host.clj
diff options
context:
space:
mode:
authorEduardo Julian2016-05-21 13:55:14 -0400
committerEduardo Julian2016-05-21 13:55:14 -0400
commit0f110f4b904f64a1c79928be2f62dbffcf699ff5 (patch)
tree422bf2e6a8819c4bcc1be22827943d18564552f8 /src/lux/type/host.clj
parent78eb074356a524248c3bac97ab2c9fbbe0d139b9 (diff)
- Fixed a bug in which it was impossible to pattern-match against existentially-qualified types.
- Improved error-reporting. - When loading a class post-compilation, the ClassLoader kept referring to the previous dummy version used during analysis, which meant the real class, with it's code, couldn't be used at compile time. Fixed this (with a hack, sadly...). - Fixed a bug in which using JVM type-vars with top-bounds different from java.lang.Object was not getting acknowledged by the compiler, and resulted in incorrect signatures for methods.
Diffstat (limited to '')
-rw-r--r--src/lux/type/host.clj33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/lux/type/host.clj b/src/lux/type/host.clj
index de5b3df84..340d805a2 100644
--- a/src/lux/type/host.clj
+++ b/src/lux/type/host.clj
@@ -6,7 +6,8 @@
(ns lux.type.host
(:require clojure.core.match
clojure.core.match.array
- (lux [base :as & :refer [|do return* return fail fail* assert! |let |case]]))
+ (lux [base :as & :refer [|do return* return fail fail* assert! |let |case]])
+ [lux.host.generics :as &host-generics])
(:import (java.lang.reflect GenericArrayType
ParameterizedType
TypeVariable
@@ -63,7 +64,7 @@
(&/fold2 matcher (&/|table) sub-type-params params)))
;; [Exports]
-(let [class-name-re #"((\[+)L([\.a-zA-Z0-9]+);|([\.a-zA-Z0-9]+)|(\[+)([ZBSIJFDC]))"
+(let [class-name-re #"((\[+)L([\.a-zA-Z0-9\$]+);|([\.a-zA-Z0-9\$]+)|(\[+)([ZBSIJFDC]))"
jprim->lprim (fn [prim]
(case prim
"Z" "boolean"
@@ -125,6 +126,34 @@
(instance-param existential matchings bound)
existential)))
+(defn principal-class [refl-type]
+ (cond (instance? Class refl-type)
+ (|case (class->type refl-type)
+ (&/$HostT "#Array" (&/$Cons (&/$HostT class-name _) (&/$Nil)))
+ (str "[" (&host-generics/->type-signature class-name))
+
+ (&/$HostT class-name _)
+ (&host-generics/->type-signature class-name)
+
+ (&/$UnitT)
+ "V")
+
+ (instance? GenericArrayType refl-type)
+ (&host-generics/->type-signature (str refl-type))
+
+ (instance? ParameterizedType refl-type)
+ (&host-generics/->type-signature (->> ^ParameterizedType refl-type ^Class (.getRawType) .getName))
+
+ (instance? TypeVariable refl-type)
+ (if-let [bound (->> ^TypeVariable refl-type .getBounds seq first)]
+ (principal-class bound)
+ (&host-generics/->type-signature "java.lang.Object"))
+
+ (instance? WildcardType refl-type)
+ (if-let [bound (->> ^WildcardType refl-type .getUpperBounds seq first)]
+ (principal-class bound)
+ (&host-generics/->type-signature "java.lang.Object"))))
+
;; TODO: CLEAN THIS UP, IT'S DOING A HACK BY TREATING GCLASSES AS GVARS
(defn instance-gtype [existential matchings gtype]
"(-> (Lux Type) (List (, Text Type)) GenericType (Lux Type))"