Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-Ywarn-numeric-widen gets triggered on case class with a Short #8340

Closed
scabug opened this issue Feb 26, 2014 · 5 comments
Closed

-Ywarn-numeric-widen gets triggered on case class with a Short #8340

scabug opened this issue Feb 26, 2014 · 5 comments
Milestone

Comments

@scabug
Copy link

scabug commented Feb 26, 2014

The following is preventing me from turning on fatal warnings, which is something I really want to do:

$ scala -Ywarn-numeric-widen
Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_45).
Type in expressions to have them evaluated.
Type :help for more information.

scala> case class A(b: Short)
<console>:7: warning: implicit numeric widening
       case class A(b: Short)
                  ^
defined class A

scala> 
@scabug
Copy link
Author

scabug commented Feb 26, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8340?orig=1
Reporter: @puffnfresh
Affected Versions: 2.10.3

@scabug
Copy link
Author

scabug commented Feb 26, 2014

@puffnfresh said:
It's to do with the hashCode:

$ scala -Ywarn-numeric-widen
Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_45).
Type in expressions to have them evaluated.
Type :help for more information.

scala> case class A(b: Short) { override def hashCode: Int = 0 }
defined class A

scala> 

The default hashCode doesn't seem to be bad, though:

override <synthetic> def hashCode(): Int = {
  <synthetic> var acc: Int = -889275714;
  acc = Statics.this.mix(acc, b.toInt);
  Statics.this.finalizeHash(acc, 1)
};

@scabug
Copy link
Author

scabug commented Feb 26, 2014

@puffnfresh said:
Fixed in master.

@scabug scabug closed this as completed May 16, 2014
@scabug
Copy link
Author

scabug commented Apr 30, 2015

Guillaume Massé (masgui) said (edited on Apr 30, 2015 5:35:20 PM UTC):
Similar bug with multiple parameters and double
scala 2.10.4

implicit numeric widening
case class A(c: Int, v: Double)
           ^

@scabug
Copy link
Author

scabug commented Feb 18, 2017

Nicolas Rinaudo (nrinaudo) said:
This still happens to me with scala 2.10.6

This generates an implicit numeric warning:

case class A(a: Char, b: Char)

This does not:

case class A(a: Char, b: Char) {
  override def hashCode: Int = 0
}

@scabug scabug added this to the 2.11.0 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant