aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Applications.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-05-22 16:56:41 +0200
committerMartin Odersky <odersky@gmail.com>2015-05-27 20:08:28 +0200
commit8dd3466ff605db006934697edd7b8ffd9af4bf7f (patch)
treeda21d3e5554d11f68aab5d118d2516053a2e01af /src/dotty/tools/dotc/typer/Applications.scala
parent6ec4b0a7753ffadaf85e4ffee0ad8bd1749cde01 (diff)
downloaddotty-8dd3466ff605db006934697edd7b8ffd9af4bf7f.tar.gz
dotty-8dd3466ff605db006934697edd7b8ffd9af4bf7f.tar.bz2
dotty-8dd3466ff605db006934697edd7b8ffd9af4bf7f.zip
Add harmonization method for harmonizing numeric types.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Applications.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Applications.scala20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala
index 855f265cc..e1d3d243d 100644
--- a/src/dotty/tools/dotc/typer/Applications.scala
+++ b/src/dotty/tools/dotc/typer/Applications.scala
@@ -1024,6 +1024,26 @@ trait Applications extends Compatibility { self: Typer =>
result
}
}
+
+ def harmonize(trees: List[Tree])(implicit ctx: Context): List[Tree] = {
+ def numericClasses(trees: List[Tree], acc: Set[Symbol]): Set[Symbol] = trees match {
+ case tree :: trees1 =>
+ val sym = tree.tpe.typeSymbol
+ if (sym.isNumericValueClass && tree.tpe.isRef(sym))
+ numericClasses(trees1, acc + sym)
+ else
+ Set()
+ case Nil =>
+ acc
+ }
+ val clss = numericClasses(trees, Set())
+ if (clss.size > 1) {
+ val lub = defn.ScalaNumericValueClassList.find(lubCls =>
+ clss.forall(defn.isValueSubClass(_, lubCls))).get.typeRef
+ trees.mapConserve(tree => adaptInterpolated(tree, lub, tree))
+ }
+ else trees
+ }
}
/*