[svn] r5930: nemerle/trunk/ncc: hierarchy/TypeInfo.n
testsuite/positive/infer.n typing/TyVarEnv.n
malekith
svnadmin at nemerle.org
Sat Nov 12 17:06:20 CET 2005
Log:
Use proper type variables in nested types (not the ones from the enclosing type). Resolves #563.
Author: malekith
Date: Sat Nov 12 17:06:04 2005
New Revision: 5930
Modified:
nemerle/trunk/ncc/hierarchy/TypeInfo.n
nemerle/trunk/ncc/testsuite/positive/infer.n
nemerle/trunk/ncc/typing/TyVarEnv.n
Modified: nemerle/trunk/ncc/hierarchy/TypeInfo.n
==============================================================================
--- nemerle/trunk/ncc/hierarchy/TypeInfo.n (original)
+++ nemerle/trunk/ncc/hierarchy/TypeInfo.n Sat Nov 12 17:06:04 2005
@@ -605,6 +605,29 @@
/** */
internal abstract SubtypingSubst (tycon : TypeInfo) : Subst;
+ /** [parent] is one of the enclosing types of [this]. For Parent['a,'b]
+ and This['a1,'b1,'c] returns ['a := 'a1, 'b := 'b1]. If there are types
+ between [parent] and [this], their type variables are also replaced. */
+ public virtual NestingSubst (parent : TypeInfo) : Subst
+ {
+ if (parent.Equals (this))
+ Subst ()
+ else {
+ def res = Subst ();
+ def cnt = parent.TyparmsCount;
+ def target = GetMemType ().args.FirstN (cnt);
+
+ def loop (ti) {
+ def source = ti.Typarms.FirstN (cnt);
+ List.Iter2 (source, target, res.Add);
+ when (! ti.Equals (parent))
+ loop (ti.DeclaringType)
+ }
+ loop (DeclaringType);
+ res
+ }
+ }
+
public abstract SuperClass () : option [TypeInfo];
/** Gets the direct base type of this type. Null if there isn't any
Modified: nemerle/trunk/ncc/testsuite/positive/infer.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/infer.n (original)
+++ nemerle/trunk/ncc/testsuite/positive/infer.n Sat Nov 12 17:06:04 2005
@@ -18,6 +18,15 @@
()
}
+ public class Set['a]
+ {
+ public class A {
+ public class B {
+ static public x : A = A();
+ }
+ }
+ }
+
public Main () : void {
def f2[a] (l) {
def arr = (System.Array.CreateInstance (typeof (a), 4) :> array [a]);
@@ -28,7 +37,7 @@
};
ignore (bb ([1], f2));
def _ = [ ([["foo"]], "foo") ] : list[_];
- ()
+ System.Console.WriteLine (Set[int].A.B.x.GetType ());
}
}
@@ -141,3 +150,9 @@
}
}
+
+/*
+BEGIN-OUTPUT
+M+Set`1+A[System.Int32]
+END-OUTPUT
+*/
Modified: nemerle/trunk/ncc/typing/TyVarEnv.n
==============================================================================
--- nemerle/trunk/ncc/typing/TyVarEnv.n (original)
+++ nemerle/trunk/ncc/typing/TyVarEnv.n Sat Nov 12 17:06:04 2005
@@ -131,11 +131,13 @@
def find_nesting (nesting : TypeInfo) {
if (nesting == null) null
else if (ti.DeclaringType.Equals (nesting))
- nesting.GetMemType ()
+ curtc.NestingSubst (nesting)
+ .Apply (nesting.GetMemType ())
else if (nesting.LookupMemberAvailable &&
nesting.LookupMember (ti.Name).Contains (ti))
- nesting.SubtypingSubst (ti)
- .Apply (ti.DeclaringType.GetMemType ())
+ curtc.NestingSubst (nesting)
+ .Apply (nesting.SubtypingSubst (ti)
+ .Apply (ti.DeclaringType.GetMemType ()).Fix ())
else find_nesting (nesting.DeclaringType)
}
match (find_nesting (curtc)) {
More information about the svn
mailing list