[svn] r7404: nemerle/trunk/ncc: hierarchy/ClassMembers.n
hierarchy/TypeBuilder.n parsing/ParseTree.n tests...
nazgul
svnadmin at nemerle.org
Sun Feb 11 13:04:05 CET 2007
Log:
Include generic parameters in implements wrapper
Author: nazgul
Date: Sun Feb 11 13:04:00 2007
New Revision: 7404
Modified:
nemerle/trunk/ncc/hierarchy/ClassMembers.n
nemerle/trunk/ncc/hierarchy/TypeBuilder.n
nemerle/trunk/ncc/parsing/ParseTree.n
nemerle/trunk/ncc/testsuite/positive/iface.n
nemerle/trunk/ncc/typing/TyVarEnv.n
nemerle/trunk/ncc/typing/TypedTree.n
Modified: nemerle/trunk/ncc/hierarchy/ClassMembers.n
==============================================================================
--- nemerle/trunk/ncc/hierarchy/ClassMembers.n (original)
+++ nemerle/trunk/ncc/hierarchy/ClassMembers.n Sun Feb 11 13:04:00 2007
@@ -911,7 +911,7 @@
def bind (t : PT.PExpr) {
when (t is <[ _ ]>)
Message.Error (t.Location, "type inference on global methods is not yet supported");
- def ty = par.MonoBindType (tenv', t);
+ def ty = f.header.typarms.Substitute (par.MonoBindType (tenv', t)).Fix ();
types_to_check ::= ty;
ty
}
Modified: nemerle/trunk/ncc/hierarchy/TypeBuilder.n
==============================================================================
--- nemerle/trunk/ncc/hierarchy/TypeBuilder.n (original)
+++ nemerle/trunk/ncc/hierarchy/TypeBuilder.n Sun Feb 11 13:04:00 2007
@@ -2276,6 +2276,7 @@
// create a wrapper in the current type
def meth_header = meth.GetHeader ();
+ def obj = if (meth.IsAbstract) <[ null : this ]> else <[ base ]>;
//Message.Debug ("additional " + meth_header.name);
def mods =
@@ -2283,16 +2284,8 @@
!(meth.Attributes %&& NemerleAttributes.Sealed))
NemerleAttributes.Override
else NemerleAttributes.New;
- def attrs = Modifiers (NemerleAttributes.Public %| mods, []);
-
- def wrapper = DefineAndReturn (<[ decl:
- ..$attrs $(meth_header.name : usesite)
- (..$(meth_header.ParametersDeclarations)) : $(meth_header.ret_type : typed)
- {
- $(if (meth.IsAbstract) <[ null : this ]> else <[ base ]>).
- $(meth_header.name : usesite) (..$(meth_header.ParametersReferences))
- }
- ]>) :> MethodBuilder;
+ def parse_tr = meth_header.CreateAliasMethod (mods | NemerleAttributes.Public, obj);
+ def wrapper = DefineAndReturn (parse_tr) :> MethodBuilder;
wrapper.MarkWithSpecialName ();
wrapper.HasBeenUsed = false; // do not trigger obsoletion warning
Modified: nemerle/trunk/ncc/parsing/ParseTree.n
==============================================================================
--- nemerle/trunk/ncc/parsing/ParseTree.n (original)
+++ nemerle/trunk/ncc/parsing/ParseTree.n Sun Feb 11 13:04:00 2007
@@ -248,6 +248,27 @@
{
if (tyvars.IsEmpty) "" else ("[" + tyvars.Map(_.ToString()).ToString(", ") + "]")
}
+
+ public virtual IsCopyOfExisting : bool { get { false } }
+ public virtual Substitute (ty : MType) : TyVar { ty }
+ public virtual ExistingTyvars : list [StaticTyVar] { get { null } }
+ }
+
+ /** The specified list of typed type parameters will be used as template for new type parameters.
+ Compiler will also perform substitution of references to old parameters in type/method signature into references
+ to fresh type parameters */
+ public class CopyTypedTyparms : Typarms {
+ fresh_vars : list [StaticTyVar];
+ subst : Subst;
+
+ public this (template_tyvars : list [StaticTyVar]) {
+ base ([], []);
+ (subst, fresh_vars) = StaticTyVar.CopyList (template_tyvars);
+ }
+
+ public override IsCopyOfExisting : bool { get { true } }
+ public override Substitute (ty : MType) : TyVar { subst.Apply (ty) }
+ public override ExistingTyvars : list [StaticTyVar] { get { fresh_vars } }
}
/** class encapsulating name of variable for purpose of
@@ -485,7 +506,7 @@
public class Fun_header : Located, IParametersProvider
{
- public typarms : Typarms;
+ public mutable typarms : Typarms;
public mutable name : Splicable; // is changed when typing lambda
public ret_type : PExpr;
public parms : list [Fun_parm];
Modified: nemerle/trunk/ncc/testsuite/positive/iface.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/iface.n (original)
+++ nemerle/trunk/ncc/testsuite/positive/iface.n Sun Feb 11 13:04:00 2007
@@ -19,3 +19,29 @@
public foo1 () : void implements A.foo {}
}
\ No newline at end of file
+
+namespace Bug881 {
+ class Base {
+ public virtual Foo[T](x : T) : list [T] {
+ System.Console.WriteLine (typeof (T));
+ [x]
+ }
+ }
+
+ interface IFace {
+ Foo[T](x : T) : list [T];
+ }
+
+ class Derived : Base, IFace {}
+}
+
+class Bar { }
+
+def d = Bug881.Derived () : Bug881.IFace;
+assert (d.Foo (Bar ()).Length == 1);
+
+/*
+BEGIN-OUTPUT
+Bar
+END-OUTPUT
+*/
\ No newline at end of file
Modified: nemerle/trunk/ncc/typing/TyVarEnv.n
==============================================================================
--- nemerle/trunk/ncc/typing/TyVarEnv.n (original)
+++ nemerle/trunk/ncc/typing/TyVarEnv.n Sun Feb 11 13:04:00 2007
@@ -379,11 +379,13 @@
f (t)
}
-
public AddTyparms (env : GlobalEnv, tp : Typarms,
curtc : TypeBuilder,
check_parms : bool) : TyVarEnv * list [StaticTyVar]
{
+ when (tp.IsCopyOfExisting)
+ Nemerle.Imperative.Return ((this, tp.ExistingTyvars));
+
def loop (tv : Splicable, acc) {
def (map, the_list) = acc;
def name = tv.GetName();
Modified: nemerle/trunk/ncc/typing/TypedTree.n
==============================================================================
--- nemerle/trunk/ncc/typing/TypedTree.n (original)
+++ nemerle/trunk/ncc/typing/TypedTree.n Sun Feb 11 13:04:00 2007
@@ -348,6 +348,20 @@
public ParametersReferences : list [Parsetree.PExpr] {
get { parms.Map (_.ReferencingExpr) }
}
+
+ public CreateAliasMethod (mods : NemerleAttributes, obj : Parsetree.PExpr) : Parsetree.ClassMember
+ {
+ def attrs = Modifiers (mods, []);
+
+ def parse_tr = <[ decl:
+ ..$attrs $(this.name : usesite) (..$(this.ParametersDeclarations)) : $(this.ret_type : typed)
+ {}
+ ]>;
+ parse_tr.header.typarms = Parsetree.CopyTypedTyparms (this.typarms);
+ def tyargs = parse_tr.header.typarms.ExistingTyvars.Map (x => <[ $(MType.TyVarRef (x) : typed) ]>);
+ parse_tr.Body = <[ $obj.$(this.name : usesite) .[..$tyargs] (..$(this.ParametersReferences)) ]>;
+ parse_tr
+ }
}
More information about the svn
mailing list