Skip to content

Report two errors when the same class is defined twice #11784

Open
@olafurpg

Description

@olafurpg

Currently, scalac reports a single error when the same class is compiled twice. Consider the following input:

// foo.scala
object Main
object Main

Running scalac reports

$ scalac foo.scala
foo.scala:2: error: Main is already defined as object Main
object Main
       ^
one error found

I expected scalac to report two errors

foo.scala:2: error: Main is already defined as object Main
object Main
       ^
+ foo.scala:1: error: Main is already defined as object Main
+ object Main
+        ^
- one error found
+ two errors found

This situation where the same class is defined twice can happen frequently in IDEs like Metals where users copy-paste a source file, example scalameta/metals#1027.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions