Skip to content

Fix #8716 and fix #8717: Add missing extension span #8720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3573,6 +3573,7 @@ object Parsers {
*/
def extensionDef(start: Offset, mods: Modifiers): ModuleDef =
in.nextToken()
val nameOffset = in.offset
val name = if isIdent && !isIdent(nme.on) then ident() else EmptyTermName
in.endMarkerScope(if name.isEmpty then nme.extension else name) {
val (tparams, vparamss, extensionFlag) =
Expand All @@ -3588,7 +3589,7 @@ object Parsers {
if !in.isNestedStart then syntaxError("Extension without extension methods")
val templ = templateBodyOpt(makeConstructor(tparams, vparamss), Nil, Nil)
templ.body.foreach(checkExtensionMethod(tparams, vparamss, _))
val edef = ModuleDef(name, templ)
val edef = atSpan(start, nameOffset, in.offset)(ModuleDef(name, templ))
finalizeDef(edef, addFlag(mods, Given | extensionFlag), start)
}

Expand Down
14 changes: 14 additions & 0 deletions compiler/test-resources/repl/i8716_i8717
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
scala>extension { }
1 |extension { }
|^
|anonymous instance must implement a type or have at least one extension method
scala> extension as on
1 | extension as on
| ^
| '(' expected, but eof found
scala> extension as on (s
1 | extension as on (s
| ^
| ':' expected, but eof found
scala> extension as on (s: String) { def expand = ??? }
// defined object as
4 changes: 2 additions & 2 deletions tests/semanticdb/expect/Givens.expect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ package b
object Givens/*<-a::b::Givens.*/:

extension on [A](any: A):
def /*<-a::b::Givens.extension_sayHello_A.*//*<-a::b::Givens.extension_sayHello_A.sayHello().[A]*//*<-a::b::Givens.extension_sayHello_A.sayHello().(any)*//*->a::b::Givens.extension_sayHello_A.sayHello().[A]*/sayHello/*<-a::b::Givens.extension_sayHello_A.sayHello().*/ = s"/*->scala::StringContext.apply().*/Hello, I am $any/*->a::b::Givens.extension_sayHello_A.sayHello().(any)*/"/*->scala::StringContext#s().*/
/*<-a::b::Givens.extension_sayHello_A.*//*<-a::b::Givens.extension_sayHello_A.sayHello().[A]*//*<-a::b::Givens.extension_sayHello_A.sayHello().(any)*//*->a::b::Givens.extension_sayHello_A.sayHello().[A]*/def sayHello/*<-a::b::Givens.extension_sayHello_A.sayHello().*/ = s"/*->scala::StringContext.apply().*/Hello, I am $any/*->a::b::Givens.extension_sayHello_A.sayHello().(any)*/"/*->scala::StringContext#s().*/

extension on [B](any: B):
def sa/*<-a::b::Givens.extension_sayGoodbye_B.*//*<-a::b::Givens.extension_sayGoodbye_B.sayGoodbye().[B]*//*<-a::b::Givens.extension_sayGoodbye_B.saySoLong().[B]*//*<-a::b::Givens.extension_sayGoodbye_B.sayGoodbye().(any)*//*<-a::b::Givens.extension_sayGoodbye_B.saySoLong().(any)*//*->a::b::Givens.extension_sayGoodbye_B.sayGoodbye().[B]*//*->a::b::Givens.extension_sayGoodbye_B.saySoLong().[B]*/yGoodbye/*<-a::b::Givens.extension_sayGoodbye_B.sayGoodbye().*/ = s"/*->scala::StringContext.apply().*/Goodbye, from $any/*->a::b::Givens.extension_sayGoodbye_B.sayGoodbye().(any)*/"/*->scala::StringContext#s().*/
de/*<-a::b::Givens.extension_sayGoodbye_B.*//*<-a::b::Givens.extension_sayGoodbye_B.sayGoodbye().[B]*//*<-a::b::Givens.extension_sayGoodbye_B.saySoLong().[B]*//*<-a::b::Givens.extension_sayGoodbye_B.sayGoodbye().(any)*//*<-a::b::Givens.extension_sayGoodbye_B.saySoLong().(any)*//*->a::b::Givens.extension_sayGoodbye_B.sayGoodbye().[B]*//*->a::b::Givens.extension_sayGoodbye_B.saySoLong().[B]*/f sayGoodbye/*<-a::b::Givens.extension_sayGoodbye_B.sayGoodbye().*/ = s"/*->scala::StringContext.apply().*/Goodbye, from $any/*->a::b::Givens.extension_sayGoodbye_B.sayGoodbye().(any)*/"/*->scala::StringContext#s().*/
def saySoLong/*<-a::b::Givens.extension_sayGoodbye_B.saySoLong().*/ = s"/*->scala::StringContext.apply().*/So Long, from $any/*->a::b::Givens.extension_sayGoodbye_B.saySoLong().(any)*/"/*->scala::StringContext#s().*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the changes here accidental?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those positions where broken before and now are broken in a slightly different way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semanticdb must be looking at the wrong tree or some position gets badly propagated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a separate issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #8725


val hello1/*<-a::b::Givens.hello1.*/ = /*->a::b::Givens.extension_sayHello_A.sayHello().*/1.sayHello
Expand Down
4 changes: 2 additions & 2 deletions tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -1308,15 +1308,15 @@ Occurrences:
[0:8..0:9): a <- a/
[1:8..1:9): b <- a/b/
[3:7..3:13): Givens <- a/b/Givens.
[5:16..6:8): <- a/b/Givens.extension_sayHello_A.
[5:12..6:4): <- a/b/Givens.extension_sayHello_A.
[5:16..5:17): A <- a/b/Givens.extension_sayHello_A.sayHello().[A]
[5:19..5:22): any <- a/b/Givens.extension_sayHello_A.sayHello().(any)
[5:24..5:25): A -> a/b/Givens.extension_sayHello_A.sayHello().[A]
[6:8..6:16): sayHello <- a/b/Givens.extension_sayHello_A.sayHello().
[6:21..6:21): -> scala/StringContext.apply().
[6:34..6:37): any -> a/b/Givens.extension_sayHello_A.sayHello().(any)
[6:37..6:38): " -> scala/StringContext#s().
[8:16..9:10): <- a/b/Givens.extension_sayGoodbye_B.
[8:12..9:6): <- a/b/Givens.extension_sayGoodbye_B.
[8:16..8:17): B <- a/b/Givens.extension_sayGoodbye_B.sayGoodbye().[B]
[8:16..8:17): B <- a/b/Givens.extension_sayGoodbye_B.saySoLong().[B]
[8:19..8:22): any <- a/b/Givens.extension_sayGoodbye_B.sayGoodbye().(any)
Expand Down