To properly implement ExplicitResultTypes #324 scalafix needs a way to confidently be able to insert a type name like Future knowing it will resolve to scala.concurrent.Future instead of some other com.bar.Future that has been imported in the enclosing scope.
With scalameta v2.1.2, Denotation.members: List[Signature] is populated for wildcard imports and Template parent constructors with scalacOption -P:semanticdb:members:all. This information should be sufficient used to reproduce lexical scoping rules of the Scala spec.
The most immediate application of this issue in scalafix would be to remove the ExplicitResultTypes.unsafeShortenName: Boolean option in favor of inserting short names by default as long as they resolve to the correct symbol. The place this can be accomplished is here https://github.com/scalacenter/scalafix/blob/e4a5c35d676aee196edd645a9f860330606ebfe7/scalafix-core/shared/src/main/scala/scalafix/internal/util/TypeSyntax.scala#L44-L55
Instead of blindly shortening names if unsafeShortenNames is enabled, we lookup the name in the scope and shorten if the name resolves to the correct symbol OR the name does not resolve to any symbol. In the future, we can accommodate more advanced functionality such a configuring that mutable collections should be prefixed with mutable or when a package should be renamed on import, etc.
To properly implement ExplicitResultTypes #324 scalafix needs a way to confidently be able to insert a type name like
Future
knowing it will resolve toscala.concurrent.Future
instead of some othercom.bar.Future
that has been imported in the enclosing scope.With scalameta v2.1.2,
Denotation.members: List[Signature]
is populated for wildcard imports and Template parent constructors with scalacOption-P:semanticdb:members:all
. This information should be sufficient used to reproduce lexical scoping rules of the Scala spec.The most immediate application of this issue in scalafix would be to remove the
ExplicitResultTypes.unsafeShortenName: Boolean
option in favor of inserting short names by default as long as they resolve to the correct symbol. The place this can be accomplished is here https://github.com/scalacenter/scalafix/blob/e4a5c35d676aee196edd645a9f860330606ebfe7/scalafix-core/shared/src/main/scala/scalafix/internal/util/TypeSyntax.scala#L44-L55 Instead of blindly shortening names ifunsafeShortenNames
is enabled, we lookup the name in the scope and shorten if the name resolves to the correct symbol OR the name does not resolve to any symbol. In the future, we can accommodate more advanced functionality such a configuring that mutable collections should be prefixed withmutable
or when a package should be renamed on import, etc.