Skip to content

int/long literal type conforms to float/double literal type with different value via type alias #18340

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

Closed
unkarjedy opened this issue Aug 3, 2023 · 2 comments · Fixed by #18360

Comments

@unkarjedy
Copy link
Contributor

Compiler version

Scala 3.3.1-RC4

Minimized code

@main def main: Unit =
  type T = 3f
  val value1: T = -100500 //BAD: compiler doesn't report an error
  val value2: T = -100500L //BAD: compiler doesn't report an error
  //val value3: T = -100500D //OK: compiler error
  //val value4: T = true //OK: compiler error

Expectation

The code shouldn't compile

The same issue for type T = 3d

@unkarjedy unkarjedy added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Aug 3, 2023
@som-snytt
Copy link
Contributor

Adjacently, I expected harmonization to kick in:

scala> val x: 3.0 = 3
-- [E007] Type Mismatch Error: -----------------------------------------------------------------------------------------
1 |val x: 3.0 = 3
  |             ^
  |             Found:    (3 : Int)
  |             Required: (3.0d : Double)
  |
  | longer explanation available when compiling with `-explain`
1 error found

scala> val x: List[3.0] = List(3)
val x: List[3.0] = List(3.0)

@unkarjedy unkarjedy changed the title int/long literal type conforms to float/double literal type with different value int/long literal type conforms to float/double literal type with different value via type alias Aug 4, 2023
@dwijnand
Copy link
Member

dwijnand commented Aug 7, 2023

The same issue for type T = 3d

Fill in the rest:

@main def main: Unit =
  type Ti = 3
  val value1i: Ti = -100500  // error
  val value2i: Ti = -100500L // error
  val value4i: Ti = -100500F // error
  val value5i: Ti = -100500D // error
  val value6i: Ti = true     // error

  type Tl = 3L
  val value1l: Tl = -100500  // should-be-error
  val value2l: Tl = -100500L // error
  val value4l: Tl = -100500F // error
  val value5l: Tl = -100500D // error
  val value6l: Tl = true     // error

  type Tf = 3f
  val value1f: Tf = -100500  // should-be-error
  val value2f: Tf = -100500L // should-be-error
  val value4f: Tf = -100500F // error
  val value5f: Tf = -100500D // error
  val value6f: Tf = true     // error

  type Td = 3d
  val value1d: Td = -100500  // should-be-error
  val value2d: Td = -100500L // should-be-error
  val value4d: Td = -100500F // should-be-error
  val value5d: Td = -100500D // error
  val value6d: Td = true     // error

As well as proving it works correctly without a type alias

@main def main: Unit =
  val lit1i: 3 = -100500  // error
  val lit2i: 3 = -100500L // error
  val lit4i: 3 = -100500F // error
  val lit5i: 3 = -100500D // error
  val lit6i: 3 = true     // error

  val lit1l: 3L = -100500  // error
  val lit2l: 3L = -100500L // error
  val lit4l: 3L = -100500F // error
  val lit5l: 3L = -100500D // error
  val lit6l: 3L = true     // error

  val lit1f: 3f = -100500  // error
  val lit2f: 3f = -100500L // error
  val lit4f: 3f = -100500F // error
  val lit5f: 3f = -100500D // error
  val lit6f: 3f = true     // error

  val lit1d: 3d = -100500  // error
  val lit2d: 3d = -100500L // error
  val lit4d: 3d = -100500F // error
  val lit5d: 3d = -100500D // error
  val lit6d: 3d = true     // error

@dwijnand dwijnand added area:typer stat:needs triage Every issue needs to have an "area" and "itype" label and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Aug 7, 2023
odersky added a commit to dotty-staging/dotty that referenced this issue Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants