Skip to content

Commit

Permalink
Disambiguate more towards new given syntax, show solution for scala#1…
Browse files Browse the repository at this point in the history
…5840

Faced with

    given C[T]:
      ...

(with a new line after `:`) we now classify this as new given syntax, and assume ... is a template body.
If one wants to use old syntax, one can still write

    given C[T]
      : ImplementedType ...

# Conflicts:
#	compiler/src/dotty/tools/dotc/parsing/Parsers.scala
  • Loading branch information
odersky committed Feb 26, 2024
1 parent 489e0d6 commit fda4304
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,6 @@ object Parsers {
lookahead.isColon
&& {
!in.featureEnabled(Feature.modularity)
|| paramsSeen
|| { // with modularity language import, a `:` at EOL after an identifier represents a single identifier given
// Example:
// given C:
Expand Down
27 changes: 27 additions & 0 deletions tests/run/i15840.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//> using options -language:experimental.modularity -source future

trait Nat:
type N <: Nat

class _0 extends Nat:
type N = _0

class NatOps[N <: Nat](tracked val n: N):
def toInt(using toIntN: ToInt[n.N]): Int = toIntN()

// works
def toInt[N <: Nat](n: N)(using toIntN: ToInt[n.N]) = toIntN()

sealed abstract class ToInt[N <: Nat]:
def apply(): Int

object ToInt:
given ToInt[_0] {
def apply() = 0
}

@main def Test() =
assert(toInt(new _0) == 0)
assert(NatOps[_0](new _0).toInt == 0)
assert:
NatOps(new _0).toInt == 0 // did not work

0 comments on commit fda4304

Please sign in to comment.