forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disambiguate more towards new given syntax, show solution for scala#1…
…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
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |