Skip to content

Commit 042ba93

Browse files
Merge pull request #9845 from dotty-staging/fix-#9839
Fix #9839: Drop old extension method syntax
2 parents 2ec7a6f + 31d7564 commit 042ba93

File tree

12 files changed

+22
-52
lines changed

12 files changed

+22
-52
lines changed

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

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3277,40 +3277,11 @@ object Parsers {
32773277
makeConstructor(Nil, vparamss, rhs).withMods(mods).setComment(in.getDocComment(start))
32783278
}
32793279
else {
3280-
var mods1 = addFlag(mods, Method)
3281-
var isInfix = false
3282-
def extParamss() =
3283-
try paramClause(0, prefix = true) :: Nil
3284-
finally
3285-
mods1 = addFlag(mods, ExtensionMethod)
3286-
if in.token == DOT then in.nextToken()
3287-
else
3288-
isInfix = true
3289-
newLineOpt()
3290-
val (leadingTparams, leadingVparamss) =
3291-
if in.token == LBRACKET then
3292-
(typeParamClause(ParamOwner.Def), extParamss())
3293-
else if in.token == LPAREN then
3294-
(Nil, extParamss())
3295-
else
3296-
(Nil, Nil)
3280+
val mods1 = addFlag(mods, Method)
32973281
val ident = termIdent()
32983282
var name = ident.name.asTermName
3299-
if mods1.is(ExtensionMethod) then name = name.toExtensionName
3300-
if isInfix && !name.isOperatorName then
3301-
val infixAnnot = Apply(wrapNew(scalaAnnotationDot(tpnme.infix)), Nil)
3302-
.withSpan(Span(start, start))
3303-
mods1 = mods1.withAddedAnnotation(infixAnnot)
3304-
val tparams =
3305-
if in.token == LBRACKET then
3306-
if mods1.is(ExtensionMethod) then syntaxError("no type parameters allowed here")
3307-
typeParamClause(ParamOwner.Def)
3308-
else leadingTparams
3309-
val vparamss = paramClauses() match
3310-
case rparams :: rparamss if leadingVparamss.nonEmpty && ident.name.isRightAssocOperatorName =>
3311-
rparams :: leadingVparamss ::: rparamss
3312-
case rparamss =>
3313-
leadingVparamss ::: rparamss
3283+
val tparams = typeParamClauseOpt(ParamOwner.Def)
3284+
val vparamss = paramClauses()
33143285
var tpt = fromWithinReturnType {
33153286
if in.token == COLONEOL then in.token = COLON
33163287
// a hack to allow

compiler/test/dotty/tools/repl/ReplCompilerTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ class ReplCompilerTests extends ReplTest {
170170
run("""
171171
|trait Ord[T] {
172172
| def compare(x: T, y: T): Int
173-
| def (x: T) < (y: T) = compare(x, y) < 0
174-
| def (x: T) > (y: T) = compare(x, y) > 0
173+
| extension (x: T) def < (y: T) = compare(x, y) < 0
174+
| extension (x: T) def > (y: T) = compare(x, y) > 0
175175
|}
176176
|
177177
|given IntOrd as Ord[Int] {

tests/pos/i7700.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ object Macros:
77
extension (sc: StringContext) inline def show(args: =>Any*): String = ???
88

99
object Show:
10-
def[A] (a: A) show(using S: Show[A]): String = S.show(a)
10+
extension [A] (a: A) def show(using S: Show[A]): String = S.show(a)
1111

1212
export Macros.show

0 commit comments

Comments
 (0)