Skip to content

Commit bf7009e

Browse files
authored
Merge pull request #12979 from dotty-staging/fix-12949
2 parents 094a3c5 + 733200e commit bf7009e

23 files changed

+119
-38
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ object desugar {
783783
DefDef(
784784
className.toTermName, joinParams(constrTparams, defParamss),
785785
classTypeRef, creatorExpr)
786-
.withMods(companionMods | mods.flags.toTermFlags & GivenOrImplicit | Synthetic | Final)
786+
.withMods(companionMods | mods.flags.toTermFlags & GivenOrImplicit | Final)
787787
.withSpan(cdef.span) :: Nil
788788
}
789789

@@ -809,7 +809,7 @@ object desugar {
809809
Nil
810810
}
811811
}
812-
val classMods = if mods.is(Given) then mods &~ Given | Synthetic else mods
812+
val classMods = if mods.is(Given) then mods | Synthetic else mods
813813
cpy.TypeDef(cdef: TypeDef)(
814814
name = className,
815815
rhs = cpy.Template(impl)(constr, parents1, clsDerived, self1,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class TreeMapWithImplicits extends tpd.TreeMap {
6363
private def nestedScopeCtx(defs: List[Tree])(using Context): Context = {
6464
val nestedCtx = ctx.fresh.setNewScope
6565
defs foreach {
66-
case d: DefTree if d.symbol.isOneOf(GivenOrImplicit) => nestedCtx.enter(d.symbol)
66+
case d: DefTree if d.symbol.isOneOf(GivenOrImplicitVal) => nestedCtx.enter(d.symbol)
6767
case _ =>
6868
}
6969
nestedCtx
@@ -74,7 +74,7 @@ class TreeMapWithImplicits extends tpd.TreeMap {
7474
new TreeTraverser {
7575
def traverse(tree: Tree)(using Context): Unit = {
7676
tree match {
77-
case d: DefTree if d.symbol.isOneOf(GivenOrImplicit) =>
77+
case d: DefTree if d.symbol.isOneOf(GivenOrImplicitVal) =>
7878
nestedCtx.enter(d.symbol)
7979
case _ =>
8080
}

compiler/src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import Scopes._
1313
import Uniques._
1414
import ast.Trees._
1515
import ast.untpd
16-
import Flags.GivenOrImplicit
1716
import util.{NoSource, SimpleIdentityMap, SourceFile, HashSet, ReusableInstance}
1817
import typer.{Implicits, ImportInfo, Inliner, SearchHistory, SearchRoot, TypeAssigner, Typer, Nullables}
1918
import Nullables._

compiler/src/dotty/tools/dotc/core/Flags.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ object Flags {
233233
val (Param @ _, TermParam @ _, TypeParam @ _) = newFlags(8, "<param>")
234234

235235
/** Labeled with `implicit` modifier (implicit value) */
236-
val (Implicit @ _, ImplicitTerm @ _, _) = newFlags(9, "implicit")
236+
val (Implicit @ _, ImplicitVal @ _, _) = newFlags(9, "implicit")
237237

238238
/** Labeled with `lazy` (a lazy val) / a trait */
239239
val (LazyOrTrait @ _, Lazy @ _, Trait @ _) = newFlags(10, "lazy", "<trait>")
@@ -321,7 +321,7 @@ object Flags {
321321
val (Extension @ _, ExtensionMethod @ _, _) = newFlags(28, "<extension>")
322322

323323
/** An inferable (`given`) parameter */
324-
val (Given @ _, _, _) = newFlags(29, "given")
324+
val (Given @ _, GivenVal @ _, _) = newFlags(29, "given")
325325

326326
/** Symbol is defined by a Java class */
327327
val (JavaDefined @ _, JavaDefinedVal @ _, _) = newFlags(30, "<java>")
@@ -568,6 +568,7 @@ object Flags {
568568
val FinalOrSealed: FlagSet = Final | Sealed
569569
val GivenOrImplicit: FlagSet = Given | Implicit
570570
val GivenOrImplicitVal: FlagSet = GivenOrImplicit.toTermFlags
571+
val GivenMethod: FlagSet = Given | Method
571572
val InlineOrProxy: FlagSet = Inline | InlineProxy // An inline method or inline argument proxy */
572573
val InlineMethod: FlagSet = Inline | Method
573574
val InlineParam: FlagSet = Inline | Param
@@ -600,7 +601,6 @@ object Flags {
600601
val Scala2Trait: FlagSet = Scala2x | Trait
601602
val SyntheticArtifact: FlagSet = Synthetic | Artifact
602603
val SyntheticCase: FlagSet = Synthetic | Case
603-
val SyntheticGivenMethod: FlagSet = Synthetic | Given | Method
604604
val SyntheticModule: FlagSet = Synthetic | Module
605605
val SyntheticOpaque: FlagSet = Synthetic | Opaque
606606
val SyntheticParam: FlagSet = Synthetic | Param

compiler/src/dotty/tools/dotc/core/Scopes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ object Scopes {
411411
var irefs = new mutable.ListBuffer[TermRef]
412412
var e = lastEntry
413413
while (e ne null) {
414-
if (e.sym.isOneOf(GivenOrImplicit)) {
414+
if (e.sym.isOneOf(GivenOrImplicitVal)) {
415415
val d = e.sym.denot
416416
irefs += TermRef(NoPrefix, d.symbol.asTerm).withDenot(d)
417417
}

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,19 @@ object SymDenotations {
711711
}
712712
)
713713

714+
/** Do this symbol and `cls` represent a pair of a given or implicit method and
715+
* its associated class that were defined by a single definition?
716+
* This can mean one of two things:
717+
* - the method and class are defined in a structural given instance, or
718+
* - the class is an implicit class and the method is its implicit conversion.
719+
*/
720+
final def isCoDefinedGiven(cls: Symbol)(using Context): Boolean =
721+
is(Method) && isOneOf(GivenOrImplicit)
722+
&& ( is(Synthetic) // previous scheme used in 3.0
723+
|| cls.isOneOf(GivenOrImplicit) // new scheme from 3.1
724+
)
725+
&& name == cls.name.toTermName && owner == cls.owner
726+
714727
/** Is this a denotation of a stable term (or an arbitrary type)?
715728
* Terms are stable if they are idempotent (as in TreeInfo.Idempotent): that is, they always return the same value,
716729
* if any.
@@ -2231,7 +2244,7 @@ object SymDenotations {
22312244
if (keepOnly eq implicitFilter)
22322245
if (this.is(Package)) Iterator.empty
22332246
// implicits in package objects are added by the overriding `memberNames` in `PackageClassDenotation`
2234-
else info.decls.iterator.filter(_.isOneOf(GivenOrImplicit))
2247+
else info.decls.iterator.filter(_.isOneOf(GivenOrImplicitVal))
22352248
else info.decls.iterator
22362249
for (sym <- ownSyms) maybeAdd(sym.name)
22372250
names

compiler/src/dotty/tools/dotc/core/TypeErrors.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class CyclicReference private (val denot: SymDenotation) extends TypeError {
141141
}
142142

143143
// Give up and give generic errors.
144-
else if (cycleSym.isOneOf(GivenOrImplicit, butNot = Method) && cycleSym.owner.isTerm)
144+
else if (cycleSym.isOneOf(GivenOrImplicitVal, butNot = Method) && cycleSym.owner.isTerm)
145145
CyclicReferenceInvolvingImplicit(cycleSym)
146146
else
147147
CyclicReferenceInvolving(denot)

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,9 @@ class TreePickler(pickler: TastyPickler) {
722722
if flags.is(Invisible) then writeModTag(INVISIBLE)
723723
if (flags.is(Erased)) writeModTag(ERASED)
724724
if (flags.is(Exported)) writeModTag(EXPORTED)
725+
if (flags.is(Given)) writeModTag(GIVEN)
726+
if (flags.is(Implicit)) writeModTag(IMPLICIT)
725727
if (isTerm) {
726-
if (flags.is(Implicit)) writeModTag(IMPLICIT)
727-
if (flags.is(Given)) writeModTag(GIVEN)
728728
if (flags.is(Lazy, butNot = Module)) writeModTag(LAZY)
729729
if (flags.is(AbsOverride)) { writeModTag(ABSTRACT); writeModTag(OVERRIDE) }
730730
if (flags.is(Mutable)) writeModTag(MUTABLE)

compiler/src/dotty/tools/dotc/interactive/Completion.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ object Completion {
323323
val extMethodsFromImplicitScope = extractMemberExtensionMethods(implicitScopeCompanions)
324324

325325
// 4. The reference is of the form r.m and the extension method is defined in some given instance in the implicit scope of the type of r.
326-
val givensInImplicitScope = implicitScopeCompanions.flatMap(_.membersBasedOnFlags(required = Given, excluded = EmptyFlags)).map(_.info)
326+
val givensInImplicitScope = implicitScopeCompanions.flatMap(_.membersBasedOnFlags(required = GivenVal, excluded = EmptyFlags)).map(_.info)
327327
val extMethodsFromGivensInImplicitScope = extractMemberExtensionMethods(givensInImplicitScope)
328328

329329
val availableExtMethods = extMethodsFromGivensInImplicitScope ++ extMethodsFromImplicitScope ++ extMethodsFromGivensInScope ++ extMethodsInScope

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class ExtractSemanticDB extends Phase:
7979
|| sym.isLocalDummy
8080
|| sym.is(Synthetic)
8181
|| sym.isSetter
82+
|| sym.isOldStyleImplicitConversion(forImplicitClassOnly = true)
83+
|| sym.owner.isGivenInstanceSummoner
8284
|| excludeDefOrUse(sym)
8385

8486
private def excludeDefOrUse(sym: Symbol)(using Context): Boolean =
@@ -102,6 +104,7 @@ class ExtractSemanticDB extends Phase:
102104
private def excludeChildren(sym: Symbol)(using Context): Boolean =
103105
!sym.exists
104106
|| sym.is(Param) && sym.info.bounds.hi.isInstanceOf[Types.HKTypeLambda]
107+
|| sym.isOldStyleImplicitConversion(forImplicitClassOnly = true)
105108

106109
/** Uses of this symbol where the reference has given span should be excluded from semanticdb */
107110
private def excludeUse(qualifier: Option[Symbol], sym: Symbol)(using Context): Boolean =

0 commit comments

Comments
 (0)