Skip to content

Commit fd8ae41

Browse files
committed
Merge GivenClass and Given
Classes can now be Given (if generated from a given def) or Implicit (if declared as an implicit class)
1 parent b536711 commit fd8ae41

File tree

7 files changed

+9
-12
lines changed

7 files changed

+9
-12
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -810,9 +810,7 @@ object desugar {
810810
}
811811
}
812812
val classMods =
813-
if mods.is(Given) then mods &~ Given | Synthetic | GivenClass
814-
else if mods.is(Implicit) then mods &~ Implicit | GivenClass
815-
else mods
813+
if mods.is(Given) then mods | Synthetic else mods
816814
cpy.TypeDef(cdef: TypeDef)(
817815
name = className,
818816
rhs = cpy.Template(impl)(constr, parents1, clsDerived, self1,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ object Flags {
315315
val (SuperParamAliasOrScala2x @ _, SuperParamAlias @ _, Scala2x @ _) = newFlags(26, "<super-param-alias>", "<scala-2.x>")
316316

317317
/** A parameter with a default value / A structural given class or an implicit class */
318-
val (_, HasDefault @ _, GivenClass @ _) = newFlags(27, "<hasdefault/given-class>")
318+
val (_, HasDefault @ _, _) = newFlags(27, "<hasdefault>")
319319

320320
/** An extension method, or a collective extension instance */
321321
val (Extension @ _, ExtensionMethod @ _, _) = newFlags(28, "<extension>")

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,8 +719,8 @@ object SymDenotations {
719719
*/
720720
final def isCoDefinedGiven(cls: Symbol)(using Context): Boolean =
721721
is(Method) && isOneOf(GivenOrImplicit)
722-
&& ( is(Synthetic) // previous scheme used in 3.0
723-
|| cls.is(GivenClass) // new scheme from 3.1
722+
&& ( is(Synthetic) // previous scheme used in 3.0
723+
|| cls.isOneOf(GivenOrImplicit) // new scheme from 3.1
724724
)
725725
&& name == cls.name.toTermName && owner == cls.owner
726726

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,9 +732,9 @@ class TreePickler(pickler: TastyPickler) {
732732
if flags.is(Invisible) then writeModTag(INVISIBLE)
733733
if (flags.is(Erased)) writeModTag(ERASED)
734734
if (flags.is(Exported)) writeModTag(EXPORTED)
735+
if (flags.is(Given)) writeModTag(GIVEN)
735736
if (isTerm) {
736737
if (flags.is(Implicit)) writeModTag(IMPLICIT)
737-
if (flags.is(Given)) writeModTag(GIVEN)
738738
if (flags.is(Lazy, butNot = Module)) writeModTag(LAZY)
739739
if (flags.is(AbsOverride)) { writeModTag(ABSTRACT); writeModTag(OVERRIDE) }
740740
if (flags.is(Mutable)) writeModTag(MUTABLE)
@@ -755,7 +755,6 @@ class TreePickler(pickler: TastyPickler) {
755755
if (flags.is(Contravariant)) writeModTag(CONTRAVARIANT)
756756
if (flags.is(Opaque)) writeModTag(OPAQUE)
757757
if (flags.is(Open)) writeModTag(OPEN)
758-
if (flags.is(GivenClass)) writeModTag(GIVEN)
759758
}
760759
}
761760

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ class TreeUnpickler(reader: TastyReader,
667667
case HASDEFAULT => addFlag(HasDefault)
668668
case STABLE => addFlag(StableRealizable)
669669
case EXTENSION => addFlag(Extension)
670-
case GIVEN => addFlag(if isType then GivenClass else Given)
670+
case GIVEN => addFlag(Given)
671671
case PARAMsetter => addFlag(ParamAccessor)
672672
case PARAMalias => addFlag(SuperParamAlias)
673673
case EXPORTED => addFlag(Exported)

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ object Checking {
473473
if (sym.is(Implicit)) {
474474
if (sym.owner.is(Package))
475475
fail(TopLevelCantBeImplicit(sym))
476-
if (sym.isType)
476+
if sym.isType && (!sym.isClass || sym.is(Trait)) then
477477
fail(TypesAndTraitsCantBeImplicit())
478478
}
479479
if sym.is(Transparent) then

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class Namer { typer: Typer =>
241241

242242
tree match {
243243
case tree: TypeDef if tree.isClassDef =>
244-
val flags = checkFlags(tree.mods.flags &~ Implicit)
244+
val flags = checkFlags(tree.mods.flags)
245245
val name = checkNoConflict(tree.name, flags.is(Private), tree.span).asTypeName
246246
val cls =
247247
createOrRefine[ClassSymbol](tree, name, flags, ctx.owner,
@@ -425,7 +425,7 @@ class Namer { typer: Typer =>
425425
* is still missing its parents. Parents are set to Nil when completion starts and are
426426
* set to the actual parents later. If a superclass completes a subclass in one
427427
* of its parents, the parents of the superclass or some intervening class might
428-
* not yet be set. This situation can be detected by asking for the baseType of Any -
428+
* not yet be set. This situation can be detected by asking for the baseType of Any -
429429
* if that type does not exist, one of the base classes of this class misses its parents.
430430
* If this situation arises, the computation of the superclass might be imprecise.
431431
* For instance, in i12722.scala, the superclass of `IPersonalCoinOps` is computed

0 commit comments

Comments
 (0)