Skip to content

Commit 3d4366f

Browse files
committed
Handle positions in extension methods
1. Take extension methods into account when checking positions. 2. Fix position of empty type tree in method definition Without this measure, the empty type tree gets the end position of the preceding element. For an extension method with type parameters this is the extension parameter list, but it should be the type parameters. Fixing the position explicitly fixes the problem.
1 parent 401931e commit 3d4366f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

compiler/src/dotty/tools/dotc/ast/Positioned.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package ast
44
import util.Positions._
55
import core.Contexts.Context
66
import core.Decorators._
7-
import core.Flags.JavaDefined
7+
import core.Flags.{JavaDefined, Extension}
88
import core.StdNames.nme
99

1010
/** A base class for things that have positions (currently: modifiers and trees)
@@ -208,6 +208,12 @@ abstract class Positioned extends Product {
208208
// Leave out tparams, they are copied with wrong positions from parent class
209209
check(tree.mods)
210210
check(tree.vparamss)
211+
case tree: DefDef if tree.mods.is(Extension) && tree.vparamss.nonEmpty =>
212+
check(tree.vparamss.head)
213+
check(tree.tparams)
214+
check(tree.vparamss.tail)
215+
check(tree.tpt)
216+
check(tree.rhs)
211217
case _ =>
212218
val end = productArity
213219
var n = 0

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ object Parsers {
10221022

10231023
def typedOpt(): Tree =
10241024
if (in.token == COLON) { in.nextToken(); toplevelTyp() }
1025-
else TypeTree()
1025+
else TypeTree().withPos(Position(in.lastOffset))
10261026

10271027
def typeDependingOn(location: Location.Value): Tree =
10281028
if (location == Location.InParens) typ()

0 commit comments

Comments
 (0)