Skip to content

Commit 89e91ae

Browse files
committed
Allow multiple context bounds in {...}
1 parent 5482680 commit 89e91ae

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,11 +2167,16 @@ object Parsers {
21672167
else atSpan((t.span union cbs.head.span).start) { ContextBounds(t, cbs) }
21682168
}
21692169

2170+
/** ContextBound ::= Type [`as` id] */
2171+
def contextBound(pname: TypeName): Tree =
2172+
ContextBoundTypeTree(toplevelTyp(), pname)
2173+
21702174
def contextBounds(pname: TypeName): List[Tree] =
21712175
if in.isColon then
2172-
atSpan(in.skipToken()) {
2173-
ContextBoundTypeTree(toplevelTyp(), pname)
2174-
} :: contextBounds(pname)
2176+
in.nextToken()
2177+
if in.token == LBRACE && in.featureEnabled(Feature.modularity)
2178+
then inBraces(commaSeparated(() => contextBound(pname)))
2179+
else contextBound(pname) :: contextBounds(pname)
21752180
else if in.token == VIEWBOUND then
21762181
report.errorOrMigrationWarning(
21772182
em"view bounds `<%' are no longer supported, use a context bound `:' instead",

tests/pos/FromString.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//> using options -language:experimental.modularity -source future
2+
3+
trait FromString:
4+
type Self
5+
def fromString(s: String): Self
6+
7+
given Int is FromString = _.toInt
8+
9+
given Double is FromString = _.toDouble
10+
11+
def add[N: {FromString, Numeric}](a: String, b: String): N =
12+
val num = summon[Numeric[N]]
13+
num.plus(N.fromString(a), N.fromString(b))

0 commit comments

Comments
 (0)