diff options
author | Martin Odersky <odersky@gmail.com> | 2015-05-23 10:20:53 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-05-27 20:08:28 +0200 |
commit | 421f29573190fca94e595bbfe30619a23b052aad (patch) | |
tree | 0247d7aa90d6176b9cd15d0331ec371d1a605d07 /src/dotty/tools/dotc/typer/Typer.scala | |
parent | 8dd3466ff605db006934697edd7b8ffd9af4bf7f (diff) | |
download | dotty-421f29573190fca94e595bbfe30619a23b052aad.tar.gz dotty-421f29573190fca94e595bbfe30619a23b052aad.tar.bz2 dotty-421f29573190fca94e595bbfe30619a23b052aad.zip |
Introduce harmonization of numeric arguments
Harmonization is Dotty's alternative to Scala 2's notion of weak conformance. It is less powerful but also
less entangled with the core type system. The idea is that in some specific contexts trees that
all have primitive numeric types will be converted as necessary so that they all have the same numeric type.
These tree sets are:
- the two branches of an if
- the alternatives of a match
- the body together with the catch blocks of a try
- the arguments of a vararg parameter
Examples are in the test file, harmonize.scala.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 9fecc9742..ea19dd1c9 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -493,7 +493,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit val cond1 = typed(tree.cond, defn.BooleanType) val thenp1 = typed(tree.thenp, pt) val elsep1 = typed(tree.elsep orElse untpd.unitLiteral withPos tree.pos, pt) - assignType(cpy.If(tree)(cond1, thenp1, elsep1), thenp1, elsep1) + val thenp2 :: elsep2 :: Nil = harmonize(thenp1 :: elsep1 :: Nil) + assignType(cpy.If(tree)(cond1, thenp2, elsep2), thenp2, elsep2) } def typedFunction(tree: untpd.Function, pt: Type)(implicit ctx: Context) = track("typedFunction") { @@ -629,7 +630,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit fullyDefinedType(sel1.tpe, "pattern selector", tree.pos)) val cases1 = typedCases(tree.cases, selType, pt) - assignType(cpy.Match(tree)(sel1, cases1), cases1) + val cases2 = harmonize(cases1).asInstanceOf[List[CaseDef]] + assignType(cpy.Match(tree)(sel1, cases2), cases2) } } @@ -737,7 +739,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit val expr1 = typed(tree.expr, pt) val cases1 = typedCases(tree.cases, defn.ThrowableType, pt) val finalizer1 = typed(tree.finalizer, defn.UnitType) - assignType(cpy.Try(tree)(expr1, cases1, finalizer1), expr1, cases1) + val expr2 :: cases2x = harmonize(expr1 :: cases1) + val cases2 = cases2x.asInstanceOf[List[CaseDef]] + assignType(cpy.Try(tree)(expr2, cases2, finalizer1), expr2, cases2) } def typedThrow(tree: untpd.Throw)(implicit ctx: Context): Tree = track("typedThrow") { |