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

Make def generated from givens not synthetic #12979

Merged
merged 10 commits into from
Aug 27, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class ExtractSemanticDB extends Phase:
|| sym.is(Synthetic)
|| sym.isSetter
|| sym.isOldStyleImplicitConversion(forImplicitClassOnly = true)
|| sym.owner.isGivenInstanceSummoner
|| excludeDefOrUse(sym)

private def excludeDefOrUse(sym: Symbol)(using Context): Boolean =
Expand Down
11 changes: 11 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/SymUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ object SymUtils:
case _ =>
false

def isGivenInstanceSummoner(using Context): Boolean =
bishabosha marked this conversation as resolved.
Show resolved Hide resolved
bishabosha marked this conversation as resolved.
Show resolved Hide resolved
def isCodefined(info: Type): Boolean = info.stripPoly match
case mt: MethodType =>
// given summoner can only have contextual params
mt.isImplicitMethod && isCodefined(mt.resultType)
case mt: ExprType =>
isCodefined(mt.resultType)
case res =>
self.isCoDefinedGiven(res.typeSymbol)
self.isAllOf(Given | Method) && isCodefined(self.info)

def useCompanionAsMirror(using Context): Boolean = self.linkedClass.exists && !self.is(Scala2x)

/** Is this a sealed class or trait for which a sum mirror is generated?
Expand Down
4 changes: 2 additions & 2 deletions tests/semanticdb/expect/InventedNames.expect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ given X/*->givens::X#*/ with
given (using X/*->givens::X#*/): Y/*->givens::Y#*/ with
def doY/*<-givens::InventedNames$package.given_Y#doY().*/ = "7"

given [T/*<-givens::InventedNames$package.given_Z_T#[T]*//*<-givens::InventedNames$package.given_Z_T().[T]*/]: Z/*->givens::Z#*/[T/*->givens::InventedNames$package.given_Z_T#[T]*/] with
given [T/*<-givens::InventedNames$package.given_Z_T#[T]*/]: Z/*->givens::Z#*/[T/*->givens::InventedNames$package.given_Z_T#[T]*/] with
def doZ/*<-givens::InventedNames$package.given_Z_T#doZ().*/: List/*->scala::package.List#*/[T/*->givens::InventedNames$package.given_Z_T#[T]*/] = Nil/*->scala::package.Nil.*/


Expand All @@ -39,4 +39,4 @@ val f/*<-givens::InventedNames$package.f.*/ = given_Float/*->givens::InventedNam
val g/*<-givens::InventedNames$package.g.*/ = `* *`/*->givens::InventedNames$package.`* *`.*/
val x/*<-givens::InventedNames$package.x.*/ = given_X/*->givens::InventedNames$package.given_X.*/
val y/*<-givens::InventedNames$package.y.*/ = given_Y/*->givens::InventedNames$package.given_Y().*/
val z/*<-givens::InventedNames$package.z.*/ = given_Z_T/*->givens::InventedNames$package.given_Z_T().*/[String/*->scala::Predef.String#*/]
val z/*<-givens::InventedNames$package.z.*/ = given_Z_T/*->givens::InventedNames$package.given_Z_T().*/[String/*->scala::Predef.String#*/]
2 changes: 1 addition & 1 deletion tests/semanticdb/expect/InventedNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ val f = given_Float
val g = `* *`
val x = given_X
val y = given_Y
val z = given_Z_T[String]
val z = given_Z_T[String]
3 changes: 1 addition & 2 deletions tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ Uri => InventedNames.scala
Text => empty
Language => Scala
Symbols => 45 entries
Occurrences => 62 entries
Occurrences => 61 entries

Symbols:
givens/InventedNames$package. => final package object givens extends Object { self: givens.type => +24 decls }
Expand Down Expand Up @@ -1767,7 +1767,6 @@ Occurrences:
[24:17..24:18): Y -> givens/Y#
[25:6..25:9): doY <- givens/InventedNames$package.given_Y#doY().
[27:7..27:8): T <- givens/InventedNames$package.given_Z_T#[T]
[27:7..27:8): T <- givens/InventedNames$package.given_Z_T().[T]
[27:11..27:12): Z -> givens/Z#
[27:13..27:14): T -> givens/InventedNames$package.given_Z_T#[T]
[28:6..28:9): doZ <- givens/InventedNames$package.given_Z_T#doZ().
Expand Down