scala / scala3

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

misleading compiler message for `:` with `-no-indent` flag #12442

Open unkarjedy opened 3 years ago

unkarjedy commented 3 years ago

Compiler version

scalaVersion := "3.0.0-RC3",
scalacOptions ++= Seq("-no-indent")

Minimized code

create simple file with indentation-based syntax for template definition of package definition

trait A:
  def f: Int

or

package bbb:
  trait A

Output

Compile the code, see the compiler message:

indented definitions expected, def found def foo = 42

The message misleads:

  1. indented definition IS actually provided: def foo is the one
  2. indented definition SHOULD NOT even be expected, because flag -no-indent is provided

Expectation

The compiler should say something like

: is not recognized

OR

{ / extends / etc... expected

OR

: is not supported with -no-indent flag

OR something else...

hartmut27 commented 2 years ago

I've encountered the error message after migration to Scala 3, when using indentation syntax:

indented definitions expected, ... found.

I could fix it by commenting out the sbt-scala3-migrate plugin in project/plugins.sbt.

...
// addSbtPlugin("ch.epfl.scala" % "sbt-scala3-migrate" % "0.5.1")
...

Then reload sbt project, then recompile project.

The error message indented definitions expected, ... found disappeared. I hope this helps :-)

Ref.: ID_RPWLKJQM4JSM

yuriy-yarosh commented 1 year ago

Started sbt-typelevel project with scala3 as the base scala version, for some reason getting the same error in the common sbt-crossproject setup for automerge-scala

So

val Scala2Version = "2.13.10"
val Scala3Version = "3.2.0"

ThisBuild / crossScalaVersions := Seq(Scala2Version, Scala3Version)
ThisBuild / scalaVersion := Scala3Version

Gives me indented definitions expected, ... found errors

while

val Scala3Version = "3.2.0"
ThisBuild / scalaVersion := Scala3Version

...does not

So, it's something sbt-crossproject related.