summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authormihaylov <mihaylov@epfl.ch>2004-09-14 09:07:32 +0000
committermihaylov <mihaylov@epfl.ch>2004-09-14 09:07:32 +0000
commitc69d97edc4940c81a4d2dff8e26cd8b74f3ec254 (patch)
tree24809e675eceddade48c6fc4d625b01221203ba1 /sources
parent92e05fabc9dff541ae3d672bf535f65c5b66c2d3 (diff)
downloadscala-c69d97edc4940c81a4d2dff8e26cd8b74f3ec254.tar.gz
scala-c69d97edc4940c81a4d2dff8e26cd8b74f3ec254.tar.bz2
scala-c69d97edc4940c81a4d2dff8e26cd8b74f3ec254.zip
- When selecting the most specific '==' method ...
- When selecting the most specific '==' method treat alse the special cases left: Byte == right: Byte -> scala.Byte.==(scala.Int) left: Short == right: Short -> scala.Short.==(scala.Int)
Diffstat (limited to 'sources')
-rw-r--r--sources/scalac/transformer/matching/CodeFactory.java85
1 files changed, 47 insertions, 38 deletions
diff --git a/sources/scalac/transformer/matching/CodeFactory.java b/sources/scalac/transformer/matching/CodeFactory.java
index 43f6bbba62..cf162a364e 100644
--- a/sources/scalac/transformer/matching/CodeFactory.java
+++ b/sources/scalac/transformer/matching/CodeFactory.java
@@ -22,41 +22,9 @@ class CodeFactory extends PatternTool {
public int pos = Position.FIRSTPOS ;
- private final Symbol CHAR_EQEQ_INT;
- private Symbol CHAR_COERCE_INT;
-
public CodeFactory( CompilationUnit unit, int pos ) {
super( unit );
this.pos = pos;
- CHAR_EQEQ_INT = getFun(defs.CHAR_CLASS.lookup(Names.EQEQ), defs.INT_TYPE());
-
- Symbol[] ss = defs.CHAR_CLASS.lookup(Names.coerce).alternativeSymbols();
- for (int i = 0; i < ss.length && CHAR_COERCE_INT == null; i++) {
- switch (ss[i].info()) {
- case MethodType(_, Type restpe):
- if (restpe.isSameAs(defs.INT_TYPE()))
- CHAR_COERCE_INT = ss[i];
- }
- }
- assert CHAR_COERCE_INT != null;
- }
-
- private Symbol getFun(Symbol sym, Type paramType) {
- Symbol fun = null;
- Type ftype = defs.ANY_TYPE();
- Symbol[] syms = sym.alternativeSymbols();
- for (int i = 0; i < syms.length; i++) {
- Symbol[] vparams = syms[i].valueParams();
- if (vparams.length == 1) {
- Type vptype = vparams[0].info();
- if (paramType.isSubType(vptype) && vptype.isSubType(ftype)) {
- fun = syms[i];
- ftype = vptype;
- }
- }
- }
- assert fun != null : Debug.show(sym.info());
- return fun;
}
// --------- these are new
@@ -213,14 +181,55 @@ class CodeFactory extends PatternTool {
return gen.mkApply_V(gen.Select(left, defs.BOOLEAN_OR()), new Tree[]{right});
}
+ // used by Equals
+ private Symbol getCoerceToInt(Type left) {
+ Symbol sym = left.lookupNonPrivate(Names.coerce);
+ assert sym != Symbol.NONE : Debug.show(left);
+ Symbol[] syms = sym.alternativeSymbols();
+ for (int i = 0; i < syms.length; i++) {
+ switch (syms[i].info()) {
+ case MethodType(Symbol[] vparams, Type restpe):
+ if (vparams.length == 0 && restpe.isSameAs(defs.INT_TYPE()))
+ return syms[i];
+ }
+ }
+ assert false : Debug.show(left);
+ return null;
+ }
+
+ // used by Equals
+ private Symbol getEqEq(Type left, Type right) {
+ Symbol sym = left.lookupNonPrivate(Names.EQEQ);
+ assert sym != Symbol.NONE
+ : Debug.show(left) + "::" + Debug.show(left.members());
+ Symbol fun = null;
+ Type ftype = defs.ANY_TYPE();
+ Symbol[] syms = sym.alternativeSymbols();
+ for (int i = 0; i < syms.length; i++) {
+ Symbol[] vparams = syms[i].valueParams();
+ if (vparams.length == 1) {
+ Type vptype = vparams[0].info();
+ if (right.isSubType(vptype) && vptype.isSubType(ftype)) {
+ fun = syms[i];
+ ftype = vptype;
+ }
+ }
+ }
+ assert fun != null : Debug.show(sym.info());
+ return fun;
+ }
+
protected Tree Equals(Tree left, Tree right) {
Type ltype = left.type.widen(), rtype = right.type.widen();
- Symbol eqsym = null;
- if (ltype.isSameAs(defs.CHAR_TYPE()) && rtype.isSameAs(defs.CHAR_TYPE())) {
- right = gen.mkApply__(gen.Select(right, CHAR_COERCE_INT));
- eqsym = CHAR_EQEQ_INT;
- } else
- eqsym = getFun(ltype.lookupNonPrivate(Names.EQEQ), rtype);
+ if (ltype.isSameAs(rtype)
+ && (ltype.isSameAs(defs.CHAR_TYPE())
+ || ltype.isSameAs(defs.BYTE_TYPE())
+ || ltype.isSameAs(defs.SHORT_TYPE())))
+ {
+ right = gen.mkApply__(gen.Select(right, getCoerceToInt(rtype)));
+ rtype = defs.INT_TYPE();
+ }
+ Symbol eqsym = getEqEq(ltype, rtype);
return gen.mkApply_V(gen.Select(left, eqsym), new Tree[]{right});
}