Skip to content
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

Fix missing SymbolOccurrence for aliased symbol #13609

Merged
merged 1 commit into from Sep 27, 2021

Conversation

tanishiking
Copy link
Member

fix #13556

Previously, we included symbols iff its name present in the source by namePresentInSource fef5be0
However, if symbols are aliased by, for example, renamed imports, there's a difference between the name of symbol and the name in source, even though they are the same symbol.

import scala.collection.immutable.{HashMap as HM}

// namePresentInSource for `HM` will be false,
// because the symbol name is `HashMap` whereas the name in the source is `HM`
val s: HM[Int, Int] = ...

We really need to exclude the symbols that never appear in the source and the gap between symbol name and name in the source should be acceptable. Therefore, this commit tries to exclude a symbol using isZeroExtent instead of namePresentInSource Actually, the diff looks fine.

fix scala#13556

Previously, we include symbols iff it's name present in source by
`namePresentInSource`.
However, if the symbol is aliased by, for example, renamed imports,
there's difference beteen the name of the symbol and the name in source
even though they are the same symbol.

What we really need to exclude are the symbols that never appear in
source, and the gap between symbol name and name in source is
acceptable.

Therefore, this commit try to exlucde symbol using `isZeroExtent`
instead of `namePresentInSource`
@@ -4,11 +4,11 @@ package b
object Givens/*<-a::b::Givens.*/:

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

Choose a reason for hiding this comment

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

Introducing StringContext#s is fine, because

Though the position is a bit wired 🤔

Copy link
Member

Choose a reason for hiding this comment

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

if i compile

def str = s"abc 123 ${scala.util.Random.nextBoolean}"

the span of .s in the desugared code is columns 10-53, so the span comes from somewhere and is truncated, maybe selectSpan or nameSpan?

either way it does not need to be fixed in this PR

@@ -1 +1,4 @@
import scala.util.control.NonFatal/*->scala::util::control::NonFatal.*/
import scala.collection.immutable.{HashMap/*->scala::collection::immutable::HashMap.*//*->scala::collection::immutable::HashMap#*/ as HM}

val m/*<-_empty_::Imports$package.m.*/: HM/*->scala::collection::immutable::HashMap#*/[Int/*->scala::Int#*/, Int/*->scala::Int#*/] = HM/*->scala::collection::immutable::HashMap.*/[Int/*->scala::Int#*/, Int/*->scala::Int#*/]()
Copy link
Member Author

Choose a reason for hiding this comment

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

Before the change, HM didn't have an occurrence.

@bishabosha bishabosha self-requested a review September 27, 2021 07:48
@bishabosha bishabosha self-assigned this Sep 27, 2021
Copy link
Member

@bishabosha bishabosha left a comment

Choose a reason for hiding this comment

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

LGTM

@bishabosha bishabosha merged commit 164b5d8 into scala:master Sep 27, 2021
@Kordyjan Kordyjan added this to the 3.1.1 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SemanticDB] Missing SymbolOccurrence of aliased class constructor
3 participants