diff options
author | schinz <schinz@epfl.ch> | 2003-08-26 07:54:01 +0000 |
---|---|---|
committer | schinz <schinz@epfl.ch> | 2003-08-26 07:54:01 +0000 |
commit | 079d579bfe054b92178cb95460541ddc016d7129 (patch) | |
tree | 71c6f9d0bb6c8ac44b640f28281546d5723f82b5 | |
parent | 24884fed2fc614581c86e147a221d5737506ff29 (diff) | |
download | scala-079d579bfe054b92178cb95460541ddc016d7129.tar.gz scala-079d579bfe054b92178cb95460541ddc016d7129.tar.bz2 scala-079d579bfe054b92178cb95460541ddc016d7129.zip |
- bug fix: try to handle multiple constructors
-rw-r--r-- | sources/scalac/transformer/AddInterfaces.java | 23 | ||||
-rw-r--r-- | sources/scalac/transformer/AddInterfacesPhase.java | 25 |
2 files changed, 32 insertions, 16 deletions
diff --git a/sources/scalac/transformer/AddInterfaces.java b/sources/scalac/transformer/AddInterfaces.java index cfe96e72ef..466c58a07d 100644 --- a/sources/scalac/transformer/AddInterfaces.java +++ b/sources/scalac/transformer/AddInterfaces.java @@ -171,10 +171,13 @@ class AddInterfaces extends Transformer { // If the constructor now refers to the interface // constructor, use the class constructor instead. Symbol clsSym = sym.constructorClass(); - if (phase.needInterface(clsSym)) - return gen.Select(qualifier, - phase.getClassSymbol(clsSym).primaryConstructor()); - else + if (phase.needInterface(clsSym)) { + Symbol realClsSym = phase.getClassSymbol(clsSym); + Map memMap = phase.getClassMemberMap(realClsSym); + assert memMap != null + : Debug.show(clsSym) + " " + Debug.show(realClsSym); + return gen.Select(qualifier, (Symbol)memMap.get(sym)); + } else return super.transform(tree); } else { qualifier = transform(qualifier); @@ -206,9 +209,15 @@ class AddInterfaces extends Transformer { // If the constructor now refers to the interface // constructor, use the class constructor instead. Symbol clsSym = sym.constructorClass(); - if (phase.needInterface(clsSym)) - return gen.Ident(phase.getClassSymbol(clsSym).primaryConstructor()); - else + if (phase.needInterface(clsSym)) { + Symbol realClsSym = phase.getClassSymbol(clsSym); + Map memMap = phase.getClassMemberMap(realClsSym); + assert memMap != null + : Debug.show(clsSym) + " " + Debug.show(realClsSym); + assert memMap.containsKey(sym) + : Debug.show(sym) + " not in " + memMap; + return gen.Ident((Symbol)memMap.get(sym)); + } else return super.transform(tree); } else if (typeSubst != null) { Symbol newSym = (Symbol)typeSubst.lookupSymbol(tree.symbol()); diff --git a/sources/scalac/transformer/AddInterfacesPhase.java b/sources/scalac/transformer/AddInterfacesPhase.java index 408aeeeca0..cb42bc15fd 100644 --- a/sources/scalac/transformer/AddInterfacesPhase.java +++ b/sources/scalac/transformer/AddInterfacesPhase.java @@ -209,9 +209,6 @@ public class AddInterfacesPhase extends Phase { classSym.name = className(ifaceSym.name); classSym.flags &= ~Modifiers.INTERFACE; - Symbol ifaceConstrSym = ifaceSym.primaryConstructor(); - Symbol classConstrSym = classSym.primaryConstructor(); - Scope ifaceOwnerMembers = ifaceSym.owner().members(); ifaceOwnerMembers.enter(classSym); @@ -220,13 +217,23 @@ public class AddInterfacesPhase extends Phase { // Create class substitution map. SymbolSubstTypeMap classSubst = newClassSubst(classSym); - classSubst.insertSymbol(ifaceConstrSym.typeParams(), - classConstrSym.typeParams()); - classSubst.insertSymbol(ifaceConstrSym.valueParams(), - classConstrSym.valueParams()); + Map classMemberMap = newClassMemberMap(classSym); + + Symbol[] allClassConstrs= + classSym.allConstructors().alternativeSymbols(); + Symbol[] allIFaceConstrs= + ifaceSym.allConstructors().alternativeSymbols(); + for (int i = 0; i < allClassConstrs.length; ++i) { + Symbol iConstr = allIFaceConstrs[i]; + Symbol cConstr = allClassConstrs[i]; + classSubst.insertSymbol(iConstr.typeParams(), + cConstr.typeParams()); + classSubst.insertSymbol(iConstr.valueParams(), + cConstr.valueParams()); + classMemberMap.put(iConstr, cConstr); + } // Clone all members, entering them in the class scope. - Map classMembersMap = newClassMemberMap(classSym); Scope classMembers = new Scope(); Scope.SymbolIterator ifaceMembersIt = new Scope.UnloadIterator(ifaceSym.members().iterator()); @@ -265,7 +272,7 @@ public class AddInterfacesPhase extends Phase { classMemberSym.info()))); } - classMembersMap.put(ifaceMemberSym, classMemberSym); + classMemberMap.put(ifaceMemberSym, classMemberSym); classMembers.enterOrOverload(classMemberSym); if (classMemberSym.isClass()) classMembers.enterOrOverload(classMemberSym.primaryConstructor()); |