scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.79k stars 1.04k forks source link

Union type: no warning for duplicate types #21240

Open kraktus opened 1 month ago

kraktus commented 1 month ago

Compiler version

3.4.2

Minimized example

type Union = Int | Int

Output Error/Warning message

No warning

Suggested improvement

-- [E006] Union Duplicate Warning: ----------------
1 | Int | Int
  | ^^    ^^
  | `Int` declared twice in union, consider removing one occurence
1 warning found

I'm not sure if this is actionable as there may be cases where it'd be desirable, with generics for example

type IntOr[T] = Int | T

but at least for concrete types I think it'd be a good warning to declutter the code (mostly an issue with long unions, and/or type alias)

soronpo commented 1 month ago

Personally, I do not see the value in this. The same way I see no value in warning x+0, x*1, true || x, etc.

kraktus commented 1 month ago

Yeah it's probably more a linter-level warning than compiler level-one.