Skip to content

Commit 064bb30

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 8a334ca commit 064bb30

File tree

7 files changed

+8
-11
lines changed

7 files changed

+8
-11
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
@@ -721,9 +721,9 @@ class TreePickler(pickler: TastyPickler) {
721721
if flags.is(Invisible) then writeModTag(INVISIBLE)
722722
if (flags.is(Erased)) writeModTag(ERASED)
723723
if (flags.is(Exported)) writeModTag(EXPORTED)
724+
if (flags.is(Given)) writeModTag(GIVEN)
724725
if (isTerm) {
725726
if (flags.is(Implicit)) writeModTag(IMPLICIT)
726-
if (flags.is(Given)) writeModTag(GIVEN)
727727
if (flags.is(Lazy, butNot = Module)) writeModTag(LAZY)
728728
if (flags.is(AbsOverride)) { writeModTag(ABSTRACT); writeModTag(OVERRIDE) }
729729
if (flags.is(Mutable)) writeModTag(MUTABLE)
@@ -744,7 +744,6 @@ class TreePickler(pickler: TastyPickler) {
744744
if (flags.is(Contravariant)) writeModTag(CONTRAVARIANT)
745745
if (flags.is(Opaque)) writeModTag(OPAQUE)
746746
if (flags.is(Open)) writeModTag(OPEN)
747-
if (flags.is(GivenClass)) writeModTag(GIVEN)
748747
}
749748
}
750749

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: 1 addition & 1 deletion
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,

0 commit comments

Comments
 (0)