scala / scala3

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

A code using given does not compile with -source:3.0-migration option #15905

Open OndrejSpanel opened 2 years ago

OndrejSpanel commented 2 years ago

Compiler version

Tested 3.0.2 and 3.1.3, both with option -source:3.0-migration, see https://scastie.scala-lang.org/04ztVOx5QuqycanJXlZQkg

Minimized code

object EnumOf {
  inline given [E](using ct: scala.reflect.ClassTag[E]): AnyRef = ???
}

Note: the code is extracted from https://github.com/theiterators/kebs/blob/master/macro-utils/src/main/scala-3/pl/iterators/kebs/macros/enums/EnumEntryMacros.scala

Output

inline must be followed by an if or a match

Expectation

Valid Scala 3 code should still compile in migration mode, or if this is not intended, the documentation should be changed. The documentation says:

option makes the compiler forgiving on most of the dropped features

There is nothing about Scala 3 features not being supported.

bishabosha commented 2 years ago

we should update the docs to say given is not supported in 3.0-migration

OndrejSpanel commented 2 years ago

we should update the docs to say given is not supported i

I searched internet and did not find a single mention about this. Could someone provide some link where this behaviour is discussed or described? What is the reason for it?

bishabosha commented 2 years ago

the biggest discussion around everything is in issue 8571: https://github.com/lampepfl/dotty/pull/8700, https://github.com/lampepfl/dotty/issues/8571

from a historical point of view, 3.0-migration used to be called Scala2Compat, as seen in #8571, originally it was meant to be for compiling the same source file under either scala 2.13 or 3.0.0, however it wasn't perfect so now there is room for a hypothetical 2x3 mode for that.

However with all of -source:3.0-migration -old-syntax -no-indent the result is pretty close