From 0f110f4b904f64a1c79928be2f62dbffcf699ff5 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 21 May 2016 13:55:14 -0400 Subject: - 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. --- src/lux/type/host.clj | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'src/lux/type/host.clj') 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))" -- cgit v1.2.3