diff options
author | Paul Phillips <paulp@improving.org> | 2013-05-27 12:02:45 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-05-27 12:54:58 -0700 |
commit | a2e8f9e001356a993da4e01235c12583d97163d3 (patch) | |
tree | c52920518cedd2ed8c38682e014dbcab683b6597 /src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala | |
parent | e42991f40707023d563f43bf66f3d8b9a637aa1b (diff) | |
download | scala-a2e8f9e001356a993da4e01235c12583d97163d3.tar.gz scala-a2e8f9e001356a993da4e01235c12583d97163d3.tar.bz2 scala-a2e8f9e001356a993da4e01235c12583d97163d3.zip |
Make all numeric coercions explicit.
Optimistically, this is preparation for a day when we don't
let numeric types drift with the winds. Even without the optimism
it's a good idea. It flushed out an undocumented change in
the math package object relative to the methods being forwarded (a
type is widened from what is returned in java) so I documented
the intentionality of it.
Managing type coercions manually is a bit tedious, no doubt,
but it's not tedious enough to warrant abandoning type safety
just because java did it.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala index 4ff3c39df3..61295b5abd 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala @@ -254,13 +254,14 @@ trait SyntheticMethods extends ast.TreeDSL { def hashcodeImplementation(sym: Symbol): Tree = { sym.tpe.finalResultType.typeSymbol match { - case UnitClass | NullClass => Literal(Constant(0)) - case BooleanClass => If(Ident(sym), Literal(Constant(1231)), Literal(Constant(1237))) - case IntClass | ShortClass | ByteClass | CharClass => Ident(sym) - case LongClass => callStaticsMethod("longHash")(Ident(sym)) - case DoubleClass => callStaticsMethod("doubleHash")(Ident(sym)) - case FloatClass => callStaticsMethod("floatHash")(Ident(sym)) - case _ => callStaticsMethod("anyHash")(Ident(sym)) + case UnitClass | NullClass => Literal(Constant(0)) + case BooleanClass => If(Ident(sym), Literal(Constant(1231)), Literal(Constant(1237))) + case IntClass => Ident(sym) + case ShortClass | ByteClass | CharClass => Select(Ident(sym), nme.toInt) + case LongClass => callStaticsMethod("longHash")(Ident(sym)) + case DoubleClass => callStaticsMethod("doubleHash")(Ident(sym)) + case FloatClass => callStaticsMethod("floatHash")(Ident(sym)) + case _ => callStaticsMethod("anyHash")(Ident(sym)) } } |