diff --git a/community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala b/community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala index a9864d0b2272..0154369438a6 100644 --- a/community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala +++ b/community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala @@ -7,7 +7,7 @@ import org.junit.{Ignore, Test} import org.junit.Assert.{assertEquals, fail} import org.junit.experimental.categories.Category -abstract class CommunityBuildTest with +abstract class CommunityBuildTest: given CommunityBuildTest = this /** Depending on the mode of operation, either @@ -81,7 +81,7 @@ abstract class CommunityBuildTest with end CommunityBuildTest @Category(Array(classOf[TestCategory])) -class CommunityBuildTestA extends CommunityBuildTest with +class CommunityBuildTestA extends CommunityBuildTest: @Test def endpoints4s = projects.endpoints4s.run() @Test def fansi = projects.fansi.run() @Test def fastparse = projects.fastparse.run() @@ -119,7 +119,7 @@ class CommunityBuildTestA extends CommunityBuildTest with end CommunityBuildTestA @Category(Array(classOf[TestCategory])) -class CommunityBuildTestB extends CommunityBuildTest with +class CommunityBuildTestB extends CommunityBuildTest: @Test def algebra = projects.algebra.run() @Test def betterfiles = projects.betterfiles.run() @Test def cats = projects.cats.run() diff --git a/compiler/src/dotty/tools/dotc/Bench.scala b/compiler/src/dotty/tools/dotc/Bench.scala index d59682afd9f5..d555ad14a493 100644 --- a/compiler/src/dotty/tools/dotc/Bench.scala +++ b/compiler/src/dotty/tools/dotc/Bench.scala @@ -11,7 +11,7 @@ import scala.annotation.internal.sharable * number of compilers and run each (sequentially) a given number of times * on the same sources. */ -object Bench extends Driver with +object Bench extends Driver: @sharable private var numRuns = 1 diff --git a/compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala b/compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala index 31d4602bc075..d6d92c3fb078 100644 --- a/compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala +++ b/compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala @@ -20,7 +20,7 @@ object DesugarEnums { val Simple, Object, Class: Value = Value } - final case class EnumConstraints(minKind: CaseKind.Value, maxKind: CaseKind.Value, enumCases: List[(Int, RefTree)]) with + final case class EnumConstraints(minKind: CaseKind.Value, maxKind: CaseKind.Value, enumCases: List[(Int, RefTree)]): require(minKind <= maxKind && !(cached && enumCases.isEmpty)) def requiresCreator = minKind == CaseKind.Simple def isEnumeration = maxKind < CaseKind.Class diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala index dd7cc6351131..62ab6d2ba844 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -943,7 +943,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => /** Extractor for not-null assertions. * A not-null assertion for reference `x` has the form `x.$asInstanceOf$[x.type & T]`. */ - object AssertNotNull with + object AssertNotNull : def apply(tree: tpd.Tree, tpnn: Type)(using Context): tpd.Tree = tree.select(defn.Any_typeCast).appliedToType(AndType(tree.tpe, tpnn)) diff --git a/compiler/src/dotty/tools/dotc/ast/Trees.scala b/compiler/src/dotty/tools/dotc/ast/Trees.scala index af3dd934903f..cde5acb2211a 100644 --- a/compiler/src/dotty/tools/dotc/ast/Trees.scala +++ b/compiler/src/dotty/tools/dotc/ast/Trees.scala @@ -382,7 +382,7 @@ object Trees { def rhs(using Context): Tree[T] = forceIfLazy } - trait ValOrTypeDef[-T >: Untyped] extends MemberDef[T] with + trait ValOrTypeDef[-T >: Untyped] extends MemberDef[T]: type ThisTree[-T >: Untyped] <: ValOrTypeDef[T] type ParamClause[T >: Untyped] = List[ValDef[T]] | List[TypeDef[T]] @@ -444,7 +444,7 @@ object Trees { } /** The kind of application */ - enum ApplyKind with + enum ApplyKind: case Regular // r.f(x) case Using // r.f(using x) case InfixTuple // r f (x1, ..., xN) where N != 1; needs to be treated specially for an error message in typedApply @@ -1591,12 +1591,12 @@ object Trees { } }.asInstanceOf[tree.ThisTree[T]] - object TypeDefs with + object TypeDefs: def unapply(xs: List[Tree]): Option[List[TypeDef]] = xs match case (x: TypeDef) :: _ => Some(xs.asInstanceOf[List[TypeDef]]) case _ => None - object ValDefs with + object ValDefs: def unapply(xs: List[Tree]): Option[List[ValDef]] = xs match case Nil => Some(Nil) case (x: ValDef) :: _ => Some(xs.asInstanceOf[List[ValDef]]) diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index bc0580346543..60201ae532a0 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -1230,12 +1230,12 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { Ident(defn.ScalaRuntimeModule.requiredMethod(name).termRef).appliedToTermArgs(args) /** An extractor that pulls out type arguments */ - object MaybePoly with + object MaybePoly: def unapply(tree: Tree): Option[(Tree, List[Tree])] = tree match case TypeApply(tree, targs) => Some(tree, targs) case _ => Some(tree, Nil) - object TypeArgs with + object TypeArgs: def unapply(ts: List[Tree]): Option[List[Tree]] = if ts.nonEmpty && ts.head.isType then Some(ts) else None diff --git a/compiler/src/dotty/tools/dotc/ast/untpd.scala b/compiler/src/dotty/tools/dotc/ast/untpd.scala index 84ef007c51af..2a00e8fd9fd1 100644 --- a/compiler/src/dotty/tools/dotc/ast/untpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/untpd.scala @@ -155,7 +155,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { } def WildcardTypeBoundsTree()(using src: SourceFile): TypeBoundsTree = TypeBoundsTree(EmptyTree, EmptyTree, EmptyTree) - object WildcardTypeBoundsTree with + object WildcardTypeBoundsTree: def unapply(tree: untpd.Tree): Boolean = tree match case TypeBoundsTree(EmptyTree, EmptyTree, _) => true case _ => false diff --git a/compiler/src/dotty/tools/dotc/config/CommandLineParser.scala b/compiler/src/dotty/tools/dotc/config/CommandLineParser.scala index e13966efe75b..e3ca896d18d2 100644 --- a/compiler/src/dotty/tools/dotc/config/CommandLineParser.scala +++ b/compiler/src/dotty/tools/dotc/config/CommandLineParser.scala @@ -6,7 +6,7 @@ import java.lang.Character.isWhitespace /** A simple enough command line parser. */ -object CommandLineParser with +object CommandLineParser: inline private val DQ = '"' inline private val SQ = '\'' inline private val EOF = -1 diff --git a/compiler/src/dotty/tools/dotc/config/Feature.scala b/compiler/src/dotty/tools/dotc/config/Feature.scala index 689a3a79065c..1984066f4f23 100644 --- a/compiler/src/dotty/tools/dotc/config/Feature.scala +++ b/compiler/src/dotty/tools/dotc/config/Feature.scala @@ -10,7 +10,7 @@ import util.SrcPos import SourceVersion._ import reporting.Message -object Feature with +object Feature: private val dependent = "dependent".toTermName private val namedTypeArguments = "namedTypeArguments".toTermName diff --git a/compiler/src/dotty/tools/dotc/config/SourceVersion.scala b/compiler/src/dotty/tools/dotc/config/SourceVersion.scala index 0abe749a946a..b6bbe512d93b 100644 --- a/compiler/src/dotty/tools/dotc/config/SourceVersion.scala +++ b/compiler/src/dotty/tools/dotc/config/SourceVersion.scala @@ -8,7 +8,7 @@ import core.StdNames.nme import core.Decorators.{_, given} import util.Property -enum SourceVersion with +enum SourceVersion: case `3.0-migration`, `3.0`, `3.1-migration`, `3.1` val isMigrating: Boolean = toString.endsWith("-migration") @@ -18,7 +18,7 @@ enum SourceVersion with def isAtLeast(v: SourceVersion) = stable.ordinal >= v.ordinal -object SourceVersion extends Property.Key[SourceVersion] with +object SourceVersion extends Property.Key[SourceVersion]: def defaultSourceVersion = `3.0` val allSourceVersionNames = values.toList.map(_.toString.toTermName) diff --git a/compiler/src/dotty/tools/dotc/core/Atoms.scala b/compiler/src/dotty/tools/dotc/core/Atoms.scala index 28dcaf96dc21..bcaaf6794107 100644 --- a/compiler/src/dotty/tools/dotc/core/Atoms.scala +++ b/compiler/src/dotty/tools/dotc/core/Atoms.scala @@ -12,7 +12,7 @@ import Types._ * If the underlying type of a singleton type is another singleton type, * only the latter type ends up in the sets. */ -enum Atoms with +enum Atoms: case Range(lo: Set[Type], hi: Set[Type]) case Unknown diff --git a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala index 5992068b8810..97b4f73cfdec 100644 --- a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala +++ b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala @@ -249,7 +249,7 @@ trait ConstraintHandling { /** Substitute wildcards with fresh TypeParamRefs, to be compared with * other bound, so that they can be instantiated. */ - object substWildcards extends TypeMap with + object substWildcards extends TypeMap: override def stopAtStatic = true var trackedPolis: List[PolyType] = Nil diff --git a/compiler/src/dotty/tools/dotc/core/ContextOps.scala b/compiler/src/dotty/tools/dotc/core/ContextOps.scala index e60b6929cc5b..34956d9294c9 100644 --- a/compiler/src/dotty/tools/dotc/core/ContextOps.scala +++ b/compiler/src/dotty/tools/dotc/core/ContextOps.scala @@ -7,7 +7,7 @@ import SymDenotations.LazyType, Names.Name, StdNames.nme import ast.untpd /** Extension methods for contexts where we want to keep the ctx. syntax */ -object ContextOps with +object ContextOps: extension (ctx: Context) diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index fd2472832c3b..a94cc44bb2aa 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -1172,7 +1172,7 @@ class Definitions { @tu lazy val TupleType: Array[TypeRef] = mkArityArray("scala.Tuple", MaxTupleArity, 1) - private class FunType(prefix: String) with + private class FunType(prefix: String): private var classRefs: Array[TypeRef] = new Array(22) def apply(n: Int): TypeRef = while n >= classRefs.length do @@ -1526,7 +1526,7 @@ class Definitions { * dependent refinements. Optionally returns a triple consisting of the argument * types `As`, the result type `B` and a whether the type is an erased context function. */ - object ContextFunctionType with + object ContextFunctionType: def unapply(tp: Type)(using Context): Option[(List[Type], Type, Boolean)] = if ctx.erasedTypes then atPhase(erasurePhase)(unapply(tp)) diff --git a/compiler/src/dotty/tools/dotc/core/NamerOps.scala b/compiler/src/dotty/tools/dotc/core/NamerOps.scala index 55b41e8553f8..8997d5ed1e1c 100644 --- a/compiler/src/dotty/tools/dotc/core/NamerOps.scala +++ b/compiler/src/dotty/tools/dotc/core/NamerOps.scala @@ -9,7 +9,7 @@ import config.Config import ast.untpd /** Operations that are shared between Namer and TreeUnpickler */ -object NamerOps with +object NamerOps: /** The given type, unless `sym` is a constructor, in which case the * type of the constructed instance is returned @@ -83,7 +83,7 @@ object NamerOps with && !cls.isAnonymousClass /** The completer of a constructor proxy apply method */ - class ApplyProxyCompleter(constr: Symbol)(using Context) extends LazyType with + class ApplyProxyCompleter(constr: Symbol)(using Context) extends LazyType: def complete(denot: SymDenotation)(using Context): Unit = denot.info = constr.info diff --git a/compiler/src/dotty/tools/dotc/core/Names.scala b/compiler/src/dotty/tools/dotc/core/Names.scala index 1ee92cb59be5..acfbd411a0ce 100644 --- a/compiler/src/dotty/tools/dotc/core/Names.scala +++ b/compiler/src/dotty/tools/dotc/core/Names.scala @@ -535,7 +535,7 @@ object Names { chrs.copyToArray(newchrs) chrs = newchrs - private class NameTable extends HashSet[SimpleName](initialCapacity = 0x10000, capacityMultiple = 2) with + private class NameTable extends HashSet[SimpleName](initialCapacity = 0x10000, capacityMultiple = 2): import util.Stats override def hash(x: SimpleName) = hashValue(chrs, x.start, x.length) // needed for resize diff --git a/compiler/src/dotty/tools/dotc/core/Substituters.scala b/compiler/src/dotty/tools/dotc/core/Substituters.scala index 61458f11d76a..f00edcb189c6 100644 --- a/compiler/src/dotty/tools/dotc/core/Substituters.scala +++ b/compiler/src/dotty/tools/dotc/core/Substituters.scala @@ -5,7 +5,7 @@ import Types._, Symbols._, Contexts._, Decorators._ /** Substitution operations on types. See the corresponding `subst` and * `substThis` methods on class Type for an explanation. */ -object Substituters with +object Substituters: final def subst(tp: Type, from: BindingType, to: BindingType, theMap: SubstBindingMap)(using Context): Type = tp match { diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 1cefefae457f..09f826c1b154 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -2556,7 +2556,7 @@ object SymDenotations { def needsCompletion(symd: SymDenotation)(using Context): Boolean = true } - object LazyType with + object LazyType: private val NoSymbolFn = (_: Context) ?=> NoSymbol /** A subtrait of LazyTypes where completerTypeParams yields a List[TypeSymbol], which diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index 5de24ce2e362..d8e107852947 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -864,7 +864,7 @@ object Symbols { /** Matches lists of term symbols, including the empty list. * All symbols in the list are assumed to be of the same kind. */ - object TermSymbols with + object TermSymbols: def unapply(xs: List[Symbol])(using Context): Option[List[TermSymbol]] = xs match case (x: Symbol) :: _ if x.isType => None case _ => Some(xs.asInstanceOf[List[TermSymbol]]) @@ -872,7 +872,7 @@ object Symbols { /** Matches lists of type symbols, excluding the empty list. * All symbols in the list are assumed to be of the same kind. */ - object TypeSymbols with + object TypeSymbols: def unapply(xs: List[Symbol])(using Context): Option[List[TypeSymbol]] = xs match case (x: Symbol) :: _ if x.isType => Some(xs.asInstanceOf[List[TypeSymbol]]) case _ => None diff --git a/compiler/src/dotty/tools/dotc/core/TypeApplications.scala b/compiler/src/dotty/tools/dotc/core/TypeApplications.scala index 45084ba53d16..d3dc0713a1ed 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeApplications.scala @@ -32,7 +32,7 @@ object TypeApplications { * * @param tycon C */ - object EtaExpansion with + object EtaExpansion: def apply(tycon: Type)(using Context): Type = assert(tycon.typeParams.nonEmpty, tycon) diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 73ca7de05f9c..91f5c2258ea7 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -2558,7 +2558,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling object TypeComparer { - enum CompareResult with + enum CompareResult: case OK, Fail, OKwithGADTUsed /** Class for unification variables used in `natValue`. */ @@ -2577,7 +2577,7 @@ object TypeComparer { * - `LoApprox`: The left type is approximated (i.e widened)" * - `HiApprox`: The right type is approximated (i.e narrowed)" */ - object ApproxState with + object ApproxState: opaque type Repr = Int val None: Repr = 0 diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index 9d8fbcbbcbe9..cfe3b80a2422 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -24,7 +24,7 @@ import reporting.TestingReporter import scala.annotation.internal.sharable import scala.annotation.threadUnsafe -object TypeOps with +object TypeOps: @sharable var track: Boolean = false // for debugging diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 98258998eb08..782a92624fe5 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -112,7 +112,7 @@ object Types { def isProvisional(using Context): Boolean = mightBeProvisional && testProvisional private def testProvisional(using Context): Boolean = - class ProAcc extends TypeAccumulator[Boolean] with + class ProAcc extends TypeAccumulator[Boolean]: override def apply(x: Boolean, t: Type) = x || test(t, this) def test(t: Type, theAcc: TypeAccumulator[Boolean]): Boolean = if t.mightBeProvisional then @@ -3413,7 +3413,7 @@ object Types { private var myParamDependencyStatus: DependencyStatus = Unknown private def depStatus(initial: DependencyStatus, tp: Type)(using Context): DependencyStatus = - class DepAcc extends TypeAccumulator[DependencyStatus] with + class DepAcc extends TypeAccumulator[DependencyStatus]: def apply(status: DependencyStatus, tp: Type) = compute(status, tp, this) def combine(x: DependencyStatus, y: DependencyStatus) = val status = (x & StatusMask) max (y & StatusMask) @@ -4419,7 +4419,7 @@ object Types { s"TypeVar($origin$instStr)" } } - object TypeVar with + object TypeVar: def apply(initOrigin: TypeParamRef, creatorState: TyperState)(using Context) = new TypeVar(initOrigin, creatorState, ctx.owner.nestingLevel) @@ -4841,7 +4841,7 @@ object Types { class CachedAnnotatedType(parent: Type, annot: Annotation) extends AnnotatedType(parent, annot) - object AnnotatedType with + object AnnotatedType: def make(underlying: Type, annots: List[Annotation])(using Context): Type = annots.foldLeft(underlying)(apply(_, _)) def apply(parent: Type, annot: Annotation)(using Context): AnnotatedType = @@ -4889,14 +4889,14 @@ object Types { def msg(using Context): Message } - object ErrorType with + object ErrorType: def apply(m: Message)(using Context): ErrorType = val et = new PreviousErrorType ctx.base.errorTypeMsg(et) = m et end ErrorType - class PreviousErrorType extends ErrorType with + class PreviousErrorType extends ErrorType: def msg(using Context): Message = ctx.base.errorTypeMsg.get(this) match case Some(m) => m @@ -5053,7 +5053,7 @@ object Types { // ----- TypeMaps -------------------------------------------------------------------- /** Common base class of TypeMap and TypeAccumulator */ - abstract class VariantTraversal with + abstract class VariantTraversal: protected[core] var variance: Int = 1 inline protected def atVariance[T](v: Int)(op: => T): T = { diff --git a/compiler/src/dotty/tools/dotc/core/Uniques.scala b/compiler/src/dotty/tools/dotc/core/Uniques.scala index 8d8a06f6fadd..5b1ae1a499e9 100644 --- a/compiler/src/dotty/tools/dotc/core/Uniques.scala +++ b/compiler/src/dotty/tools/dotc/core/Uniques.scala @@ -6,7 +6,7 @@ import config.Config import Decorators._ import util.{HashSet, Stats} -class Uniques extends HashSet[Type](Config.initialUniquesCapacity) with +class Uniques extends HashSet[Type](Config.initialUniquesCapacity): override def hash(x: Type): Int = x.hash override def isEqual(x: Type, y: Type) = x.eql(y) @@ -15,7 +15,7 @@ class Uniques extends HashSet[Type](Config.initialUniquesCapacity) with * All sets offer a `enterIfNew` method which checks whether a type * with the given parts exists already and creates a new one if not. */ -object Uniques with +object Uniques: private inline def recordCaching(tp: Type): Unit = recordCaching(tp.hash, tp.getClass) private inline def recordCaching(h: Int, clazz: Class[?]): Unit = @@ -32,7 +32,7 @@ object Uniques with if tp.hash == NotCached then tp else ctx.uniques.put(tp).asInstanceOf[T] - final class NamedTypeUniques extends HashSet[NamedType](Config.initialUniquesCapacity * 4) with Hashable with + final class NamedTypeUniques extends HashSet[NamedType](Config.initialUniquesCapacity * 4) with Hashable: override def hash(x: NamedType): Int = x.hash def enterIfNew(prefix: Type, designator: Designator, isTerm: Boolean)(using Context): NamedType = @@ -53,7 +53,7 @@ object Uniques with addEntryAt(idx, newType) end NamedTypeUniques - final class AppliedUniques extends HashSet[AppliedType](Config.initialUniquesCapacity * 2) with Hashable with + final class AppliedUniques extends HashSet[AppliedType](Config.initialUniquesCapacity * 2) with Hashable: override def hash(x: AppliedType): Int = x.hash def enterIfNew(tycon: Type, args: List[Type]): AppliedType = diff --git a/compiler/src/dotty/tools/dotc/core/tasty/CommentPickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/CommentPickler.scala index ec0514160a4b..068def1abdbd 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/CommentPickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/CommentPickler.scala @@ -10,7 +10,7 @@ import dotty.tools.tasty.TastyFormat.CommentsSection import java.nio.charset.StandardCharsets -class CommentPickler(pickler: TastyPickler, addrOfTree: tpd.Tree => Addr, docString: untpd.MemberDef => Option[Comment]) with +class CommentPickler(pickler: TastyPickler, addrOfTree: tpd.Tree => Addr, docString: untpd.MemberDef => Option[Comment]): private val buf = new TastyBuffer(5000) pickler.newSection(CommentsSection, buf) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/PositionPickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/PositionPickler.scala index d3d6444ae574..7181687d2a99 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/PositionPickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/PositionPickler.scala @@ -130,8 +130,8 @@ class PositionPickler( traverse(root, NoSource) } } -object PositionPickler with +object PositionPickler: // Note: This could be just TreeToAddr => Addr if functions are specialized to value classes. // We use a SAM type to avoid boxing of Addr - @FunctionalInterface trait TreeToAddr with + @FunctionalInterface trait TreeToAddr: def apply(x: untpd.Tree): Addr diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala index 1caa3c0cb517..3a482309e0c3 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala @@ -12,7 +12,7 @@ import util.Spans.offsetToInt import printing.Highlighting._ import dotty.tools.tasty.TastyFormat.{ASTsSection, PositionsSection, CommentsSection} -object TastyPrinter with +object TastyPrinter: def show(bytes: Array[Byte])(using Context): String = val printer = if ctx.settings.color.value == "never" then new TastyPrinter(bytes) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index a6679ed98193..f299d73758a1 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -45,7 +45,7 @@ object Parsers { def nonePositive: Boolean = parCounts forall (_ <= 0) } - enum Location(val inParens: Boolean, val inPattern: Boolean, val inArgs: Boolean) with + enum Location(val inParens: Boolean, val inPattern: Boolean, val inArgs: Boolean): case InParens extends Location(true, false, false) case InArgs extends Location(true, false, true) case InPattern extends Location(false, true, false) @@ -196,7 +196,6 @@ object Parsers { def isTemplateIntro = templateIntroTokens contains in.token def isDclIntro = dclIntroTokens contains in.token def isStatSeqEnd = in.isNestedEnd || in.token == EOF || in.token == RPAREN - def isTemplateBodyStart = in.token == WITH || in.isNestedStart def mustStartStat = mustStartStatTokens contains in.token /** Is current token a hard or soft modifier (in modifier position or not)? */ @@ -920,53 +919,6 @@ object Parsers { val next = in.lookahead.token next == LBRACKET || next == LPAREN - private def withEndMigrationWarning(): Boolean = - migrateTo3 - && { - warning( - em"""In Scala 3, `with` at the end of a line will start definitions, - |so it cannot be used in front of a parent constructor anymore. - |Place the `with` at the beginning of the next line instead.""") - true - } - - /** Does a template start after `with`? This is the case if either - * - the next token is `{` - * - the `with` is at the end of a line - * (except for source = 3.0-migration, when a warning is issued) - * - the next tokens is `` or `this` and the one after it is `:` or `=>` - * (i.e. we see the start of a self type) - */ - def followingIsTemplateStart() = - val lookahead = in.LookaheadScanner() - lookahead.nextToken() - lookahead.token == LBRACE - || lookahead.isAfterLineEnd && !withEndMigrationWarning() - || (lookahead.isIdent || lookahead.token == THIS) - && { - lookahead.nextToken() - lookahead.token == COLON - && { // needed only as long as we support significant colon at eol - lookahead.nextToken() - !lookahead.isAfterLineEnd - } - || lookahead.token == ARROW - } - - /** Does a refinement start after `with`? This is the case if either - * - the next token is `{` - * - the `with` is at the end of a line and is followed by a token that starts a declaration - */ - def followingIsRefinementStart() = - val lookahead = in.LookaheadScanner() - lookahead.nextToken() - lookahead.token == LBRACE - || lookahead.isAfterLineEnd - && { - if lookahead.token == INDENT then lookahead.nextToken() - dclIntroTokens.contains(lookahead.token) - } - /* --------- OPERAND/OPERATOR STACK --------------------------------------- */ var opStack: List[OpInfo] = Nil @@ -1329,14 +1281,14 @@ object Parsers { in.sourcePos()) patch(source, Span(in.offset), " ") - def possibleTemplateStart(): Unit = + def possibleTemplateStart(isNew: Boolean = false): Unit = in.observeColonEOL() - if in.token == COLONEOL then + if in.token == COLONEOL || in.token == WITH then if in.lookahead.isIdent(nme.end) then in.token = NEWLINE else in.nextToken() if in.token != INDENT && in.token != LBRACE then - syntaxErrorOrIncomplete(ExpectedTokenButFound(INDENT, in.token)) + syntaxErrorOrIncomplete(i"indented definitions expected, ${in} found") else newLineOptWhenFollowedBy(LBRACE) @@ -1580,29 +1532,33 @@ object Parsers { def infixTypeRest(t: Tree): Tree = infixOps(t, canStartTypeTokens, refinedType, isType = true, isOperator = !isPostfixStar) - /** RefinedType ::= WithType {[nl | ‘with’] Refinement} + /** RefinedType ::= WithType {[nl] Refinement} */ val refinedType: () => Tree = () => refinedTypeRest(withType()) - def refinedTypeRest(t: Tree): Tree = + def refinedTypeRest(t: Tree): Tree = { argumentStart() - if isTemplateBodyStart then - if in.token == WITH then in.nextToken() + if (in.isNestedStart) refinedTypeRest(atSpan(startOffset(t)) { RefinedTypeTree(rejectWildcardType(t), refinement(indentOK = true)) }) else t + } /** WithType ::= AnnotType {`with' AnnotType} (deprecated) */ def withType(): Tree = withTypeRest(annotType()) def withTypeRest(t: Tree): Tree = - if in.token == WITH && !followingIsRefinementStart() then - in.nextTokenNoIndent() - if sourceVersion.isAtLeast(`3.1`) then - deprecationWarning(DeprecatedWithOperator()) - atSpan(startOffset(t)) { makeAndType(t, withType()) } + if in.token == WITH then + val withOffset = in.offset + in.nextToken() + if in.token == LBRACE || in.token == INDENT then + t + else + if sourceVersion.isAtLeast(`3.1`) then + deprecationWarning(DeprecatedWithOperator(), withOffset) + atSpan(startOffset(t)) { makeAndType(t, withType()) } else t /** AnnotType ::= SimpleType {Annotation} @@ -2357,11 +2313,13 @@ object Parsers { val start = in.skipToken() def reposition(t: Tree) = t.withSpan(Span(start, in.lastOffset)) possibleTemplateStart() - val parents = if isTemplateBodyStart then Nil else constrApp() :: withConstrApps() + val parents = + if in.isNestedStart then Nil + else constrApps(commaOK = false) colonAtEOLOpt() - possibleTemplateStart() + possibleTemplateStart(isNew = true) parents match { - case parent :: Nil if !isTemplateBodyStart => + case parent :: Nil if !in.isNestedStart => reposition(if (parent.isType) ensureApplied(wrapNew(parent)) else parent) case _ => New(reposition(templateBodyOpt(emptyConstructor, parents, Nil))) @@ -3536,7 +3494,7 @@ object Parsers { val parents = if (in.token == EXTENDS) { in.nextToken() - constrApps() + constrApps(commaOK = true) } else Nil Template(constr, parents, Nil, EmptyValDef, Nil) @@ -3559,7 +3517,7 @@ object Parsers { syntaxError(i"extension clause can only define methods", stat.span) } - /** GivenDef ::= [GivenSig] (AnnotType [‘=’ Expr] | ConstrApps TemplateBody) + /** GivenDef ::= [GivenSig] (AnnotType [‘=’ Expr] | StructuralInstance) * GivenSig ::= [id] [DefTypeParamClause] {UsingParamClauses} ‘:’ */ def givenDef(start: Offset, mods: Modifiers, givenMod: Mod) = atSpan(start, nameStart) { @@ -3579,9 +3537,8 @@ object Parsers { if !(name.isEmpty && noParams) then accept(COLON) val parents = if isSimpleLiteral then rejectWildcardType(annotType()) :: Nil - else constrApps() + else constrApp() :: withConstrApps() val parentsIsType = parents.length == 1 && parents.head.isType - newLineOptWhenFollowedBy(LBRACE) if in.token == EQUALS && parentsIsType then accept(EQUALS) mods1 |= Final @@ -3590,17 +3547,17 @@ object Parsers { ValDef(name, parents.head, subExpr()) else DefDef(name, joinParams(tparams, vparamss), parents.head, subExpr()) - else if isTemplateBodyStart then + else if in.token != WITH && parentsIsType then + if name.isEmpty then + syntaxError(em"anonymous given cannot be abstract") + DefDef(name, joinParams(tparams, vparamss), parents.head, EmptyTree) + else val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal)) val vparamss1 = vparamss.map(_.map(vparam => vparam.withMods(vparam.mods &~ Param | ParamAccessor | Protected))) - val templ = templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil) + val templ = withTemplate(makeConstructor(tparams1, vparamss1), parents) if noParams then ModuleDef(name, templ) else TypeDef(name.toTypeName, templ) - else - if name.isEmpty then - syntaxError(em"anonymous given cannot be abstract") - DefDef(name, joinParams(tparams, vparamss), parents.head, EmptyTree) end gdef finalizeDef(gdef, mods1, start) } @@ -3619,11 +3576,8 @@ object Parsers { isUsingClause(extParams) do () leadParamss ++= paramClauses(givenOnly = true, numLeadParams = nparams) - if in.token == WITH then - syntaxError( - i"""No `with` expected here. - | - |An extension clause is simply followed by one or more method definitions.""") + if in.token == COLON then + syntaxError("no `:` expected here") in.nextToken() val methods = if isDefIntro(modifierTokens) then @@ -3674,22 +3628,23 @@ object Parsers { /** ConstrApps ::= ConstrApp ({‘,’ ConstrApp} | {‘with’ ConstrApp}) */ - def constrApps(): List[Tree] = + def constrApps(commaOK: Boolean): List[Tree] = val t = constrApp() - val ts = if in.token == COMMA then commaConstrApps() else withConstrApps() + val ts = + if in.token == WITH || commaOK && in.token == COMMA then + in.nextToken() + constrApps(commaOK) + else Nil t :: ts - /** `{`,` ConstrApp} */ - def commaConstrApps(): List[Tree] = - if in.token == COMMA then - in.nextToken() - constrApp() :: commaConstrApps() - else Nil /** `{`with` ConstrApp} but no EOL allowed after `with`. */ def withConstrApps(): List[Tree] = - if in.token == WITH && !followingIsTemplateStart() then + def isTemplateStart = + val la = in.lookahead + la.isAfterLineEnd || la.token == LBRACE + if in.token == WITH && !isTemplateStart then in.nextToken() constrApp() :: withConstrApps() else Nil @@ -3707,7 +3662,7 @@ object Parsers { in.sourcePos()) Nil } - else constrApps() + else constrApps(commaOK = true) } else Nil newLinesOptWhenFollowedBy(nme.derives) @@ -3733,20 +3688,18 @@ object Parsers { template(constr) else possibleTemplateStart() - if isTemplateBodyStart then + if in.isNestedStart then template(constr) else checkNextNotIndented() Template(constr, Nil, Nil, EmptyValDef, Nil) - /** TemplateBody ::= [nl | ‘with’] `{' TemplateStatSeq `}' - * | ‘with’ [SelfType] indent TemplateStats outdent - * EnumBody ::= [nl | ‘with’] ‘{’ [SelfType] EnumStats ‘}’ - * | ‘with’ [SelfType] indent EnumStats outdent + /** TemplateBody ::= [nl] `{' TemplateStatSeq `}' + * EnumBody ::= [nl] ‘{’ [SelfType] EnumStat {semi EnumStat} ‘}’ */ def templateBodyOpt(constr: DefDef, parents: List[Tree], derived: List[Tree]): Template = val (self, stats) = - if isTemplateBodyStart then + if in.isNestedStart then templateBody() else checkNextNotIndented() @@ -3754,44 +3707,20 @@ object Parsers { Template(constr, parents, derived, self, stats) def templateBody(): (ValDef, List[Tree]) = - val givenSelf = - if in.token == WITH then - in.nextToken() - selfDefOpt() - else EmptyValDef - val r = inDefScopeBraces(templateStatSeq(givenSelf), rewriteWithColon = true) + val r = inDefScopeBraces(templateStatSeq(), rewriteWithColon = true) if in.token == WITH then syntaxError(EarlyDefinitionsNotSupported()) in.nextToken() template(emptyConstructor) r - /** SelfType ::= id [‘:’ InfixType] ‘=>’ - * | ‘this’ ‘:’ InfixType ‘=>’ - * Only called immediately after a `with`, in which case it must in turn - * be followed by `INDENT`. - */ - def selfDefOpt(): ValDef = atSpan(in.offset) { - val vd = - if in.isIdent then - val selfName = ident() - if in.token == COLON then - in.nextToken() - makeSelfDef(selfName, infixType()) - else - makeSelfDef(selfName, TypeTree()) - else if in.token == THIS then - in.nextToken() - accept(COLON) - makeSelfDef(nme.WILDCARD, infixType()) - else - EmptyValDef - if !vd.isEmpty then - accept(ARROW) - if in.token != INDENT then - syntaxErrorOrIncomplete(ExpectedTokenButFound(INDENT, in.token)) - vd - } + /** with Template, with EOL interpreted */ + def withTemplate(constr: DefDef, parents: List[Tree]): Template = + if in.token != WITH then syntaxError(em"`with` expected") + possibleTemplateStart() // consumes a WITH token + val (self, stats) = templateBody() + Template(constr, parents, Nil, self, stats) + .withSpan(Span(constr.span.orElse(parents.head.span).start, in.lastOffset)) /* -------- STATSEQS ------------------------------------------- */ @@ -3858,10 +3787,10 @@ object Parsers { * EnumStat ::= TemplateStat * | Annotations Modifiers EnumCase */ - def templateStatSeq(givenSelf: ValDef = EmptyValDef): (ValDef, List[Tree]) = checkNoEscapingPlaceholders { - var self = givenSelf + def templateStatSeq(): (ValDef, List[Tree]) = checkNoEscapingPlaceholders { + var self: ValDef = EmptyValDef val stats = new ListBuffer[Tree] - if (self.isEmpty && isExprIntro && !isDefIntro(modifierTokens)) { + if (isExprIntro && !isDefIntro(modifierTokens)) { val first = expr1() if (in.token == ARROW) { first match { @@ -3872,20 +3801,12 @@ object Parsers { if (name != nme.ERROR) self = makeSelfDef(name, tpt).withSpan(first.span) } - in.nextTokenNoIndent() + in.token = SELFARROW // suppresses INDENT insertion after `=>` + in.nextToken() } else { stats += first - if in.token == WITH then - syntaxError( - i"""end of statement expected but ${showToken(WITH)} found - | - |Maybe you meant to write a mixin in an extends clause? - |Note that this requires the `with` to come first now. - |I.e. - | - | with $first""") - else acceptStatSepUnlessAtEnd(stats) + acceptStatSepUnlessAtEnd(stats) } } var exitOnError = false @@ -4013,7 +3934,7 @@ object Parsers { possibleTemplateStart() if in.token == EOF then ts += makePackaging(start, pkg, List()) - else if isTemplateBodyStart then + else if in.isNestedStart then ts += inDefScopeBraces(makePackaging(start, pkg, topStatSeq()), rewriteWithColon = true) continue = true else @@ -4051,7 +3972,6 @@ object Parsers { } override def templateBody(): (ValDef, List[Thicket]) = { - if in.token == WITH then in.nextToken() skipBraces() (EmptyValDef, List(EmptyTree)) } diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index 6f09a11f827f..2c9c0cabf1e9 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -323,11 +323,6 @@ object Scanners { printState() } - /** Like nextToken, but don't insert indent characters afterwards */ - def nextTokenNoIndent(): Unit = - token = EMPTY // this will suppress newline and indent insertion - nextToken() - final def printState() = if debugTokenStream && (showLookAheadOnDebug || !isInstanceOf[LookaheadScanner]) then print(s"[$show${if isInstanceOf[LookaheadScanner] then "(LA)" else ""}]") @@ -498,6 +493,8 @@ object Scanners { if canStartIndentTokens.contains(lastToken) then currentRegion = Indented(nextWidth, Set(), lastToken, currentRegion) insert(INDENT, offset) + else if lastToken == SELFARROW then + currentRegion.knownWidth = nextWidth else if (lastWidth != nextWidth) errorButContinue(spaceTabMismatchMsg(lastWidth, nextWidth)) currentRegion match { @@ -1341,7 +1338,7 @@ object Scanners { * InBraces a pair of braces { ... } * Indented a pair of ... tokens */ - abstract class Region with + abstract class Region: /** The region enclosing this one, or `null` for the outermost region */ def outer: Region | Null @@ -1380,7 +1377,7 @@ object Scanners { * @param others Other indendation widths > width of lines in the same region * @param prefix The token before the initial of the region */ - case class Indented(width: IndentWidth, others: Set[IndentWidth], prefix: Token, outer: Region | Null) extends Region with + case class Indented(width: IndentWidth, others: Set[IndentWidth], prefix: Token, outer: Region | Null) extends Region: knownWidth = width def topLevelRegion(width: IndentWidth) = Indented(width, Set(), EMPTY, null) diff --git a/compiler/src/dotty/tools/dotc/parsing/Tokens.scala b/compiler/src/dotty/tools/dotc/parsing/Tokens.scala index bcaaaeda805f..c5f77533094d 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Tokens.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Tokens.scala @@ -204,6 +204,7 @@ object Tokens extends TokensCommon { final val QUOTE = 87; enter(QUOTE, "'") final val COLONEOL = 88; enter(COLONEOL, ":", ": at eol") + final val SELFARROW = 89; enter(SELFARROW, "=>") // reclassified ARROW following self-type /** XML mode */ final val XMLSTART = 99; enter(XMLSTART, "$XMLSTART$<") // TODO: deprecate diff --git a/compiler/src/dotty/tools/dotc/printing/Formatting.scala b/compiler/src/dotty/tools/dotc/printing/Formatting.scala index 2544cde46ab2..be25469c549d 100644 --- a/compiler/src/dotty/tools/dotc/printing/Formatting.scala +++ b/compiler/src/dotty/tools/dotc/printing/Formatting.scala @@ -71,7 +71,7 @@ object Formatting { * like concatenation, stripMargin etc on the values returned by em"...", and in the current error * message composition methods, this is crucial. */ - class ErrorMessageFormatter(sc: StringContext) extends StringFormatter(sc) with + class ErrorMessageFormatter(sc: StringContext) extends StringFormatter(sc): override protected def showArg(arg: Any)(using Context): String = wrapNonSensical(arg, super.showArg(arg)(using errorMessageCtx)) diff --git a/compiler/src/dotty/tools/dotc/printing/MessageLimiter.scala b/compiler/src/dotty/tools/dotc/printing/MessageLimiter.scala index 31056cd56b65..0fcd6a800c9b 100644 --- a/compiler/src/dotty/tools/dotc/printing/MessageLimiter.scala +++ b/compiler/src/dotty/tools/dotc/printing/MessageLimiter.scala @@ -7,7 +7,7 @@ import Contexts._ import util.Property import Texts.Text -abstract class MessageLimiter with +abstract class MessageLimiter: protected def recurseLimit = 100 protected var recurseCount: Int = 0 @@ -29,17 +29,17 @@ abstract class MessageLimiter with object MessageLimiter extends Property.Key[MessageLimiter] -class DefaultMessageLimiter extends MessageLimiter with +class DefaultMessageLimiter extends MessageLimiter: override def recursionLimitExceeded()(using Context): Unit = if ctx.debug then report.warning("Exceeded recursion depth attempting to print.") Thread.dumpStack() -class SummarizeMessageLimiter(depth: Int) extends MessageLimiter with +class SummarizeMessageLimiter(depth: Int) extends MessageLimiter: override val recurseLimit = recurseCount + depth override def recursionLimitExceeded()(using Context): Unit = () -class ErrorMessageLimiter extends MessageLimiter with +class ErrorMessageLimiter extends MessageLimiter: private val initialRecurseLimit = 50 private val sizeLimit = 10000 diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteUtils.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteUtils.scala index 309f6946a16d..56c8d3347205 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteUtils.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteUtils.scala @@ -6,7 +6,7 @@ import dotty.tools.dotc.core.Contexts._ import dotty.tools.dotc.core.Decorators._ import dotty.tools.dotc.core.Symbols._ -object QuoteUtils with +object QuoteUtils: import tpd._ /** Get the owner of a tree if it has one */ diff --git a/compiler/src/dotty/tools/dotc/report.scala b/compiler/src/dotty/tools/dotc/report.scala index 228b2373fd1d..61e5dde75ad6 100644 --- a/compiler/src/dotty/tools/dotc/report.scala +++ b/compiler/src/dotty/tools/dotc/report.scala @@ -11,7 +11,7 @@ import config.Feature.sourceVersion import java.lang.System.currentTimeMillis -object report with +object report: /** For sending messages that are printed only if -verbose is set */ def inform(msg: => String, pos: SrcPos = NoSourcePosition)(using Context): Unit = diff --git a/compiler/src/dotty/tools/dotc/reporting/Diagnostic.scala b/compiler/src/dotty/tools/dotc/reporting/Diagnostic.scala index 176266fa6c4f..f31b0af14c5f 100644 --- a/compiler/src/dotty/tools/dotc/reporting/Diagnostic.scala +++ b/compiler/src/dotty/tools/dotc/reporting/Diagnostic.scala @@ -9,7 +9,7 @@ import interfaces.Diagnostic.{ERROR, INFO, WARNING} import java.util.Optional -object Diagnostic with +object Diagnostic: def shouldExplain(dia: Diagnostic)(using Context): Boolean = dia.msg.explanation.nonEmpty && ctx.settings.explain.value diff --git a/compiler/src/dotty/tools/dotc/reporting/ExploringReporter.scala b/compiler/src/dotty/tools/dotc/reporting/ExploringReporter.scala index ee75f09eb2ba..e7b636cddf02 100644 --- a/compiler/src/dotty/tools/dotc/reporting/ExploringReporter.scala +++ b/compiler/src/dotty/tools/dotc/reporting/ExploringReporter.scala @@ -7,7 +7,7 @@ import core.Contexts.Context import Diagnostic._ /** A re-usable Reporter used in Contexts#test */ -class ExploringReporter extends StoreReporter(null) with +class ExploringReporter extends StoreReporter(null): infos = new mutable.ListBuffer[Diagnostic] override def hasUnreportedErrors: Boolean = diff --git a/compiler/src/dotty/tools/dotc/reporting/TestReporter.scala b/compiler/src/dotty/tools/dotc/reporting/TestReporter.scala index b543b811e756..8ad5b525de5c 100644 --- a/compiler/src/dotty/tools/dotc/reporting/TestReporter.scala +++ b/compiler/src/dotty/tools/dotc/reporting/TestReporter.scala @@ -6,7 +6,7 @@ import collection.mutable import Diagnostic._ /** A re-usable Reporter used in Contexts#test */ -class TestingReporter extends StoreReporter(null) with +class TestingReporter extends StoreReporter(null): infos = new mutable.ListBuffer[Diagnostic] override def hasUnreportedErrors: Boolean = infos.exists(_.isInstanceOf[Error]) def reset(): Unit = infos.clear() diff --git a/compiler/src/dotty/tools/dotc/reporting/messages.scala b/compiler/src/dotty/tools/dotc/reporting/messages.scala index 4d64e65f5d99..b06bdfea1621 100644 --- a/compiler/src/dotty/tools/dotc/reporting/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/messages.scala @@ -38,36 +38,36 @@ import transform.SymUtils._ * ``` */ - abstract class SyntaxMsg(errorId: ErrorMessageID) extends Message(errorId) with + abstract class SyntaxMsg(errorId: ErrorMessageID) extends Message(errorId): def kind = "Syntax" - abstract class TypeMsg(errorId: ErrorMessageID) extends Message(errorId) with + abstract class TypeMsg(errorId: ErrorMessageID) extends Message(errorId): def kind = "Type" - abstract class TypeMismatchMsg(errorId: ErrorMessageID) extends Message(errorId) with + abstract class TypeMismatchMsg(errorId: ErrorMessageID) extends Message(errorId): def kind = "Type Mismatch" - abstract class NamingMsg(errorId: ErrorMessageID) extends Message(errorId) with + abstract class NamingMsg(errorId: ErrorMessageID) extends Message(errorId): def kind = "Naming" - abstract class DeclarationMsg(errorId: ErrorMessageID) extends Message(errorId) with + abstract class DeclarationMsg(errorId: ErrorMessageID) extends Message(errorId): def kind = "Declaration" /** A simple not found message (either for idents, or member selection. * Messages of this class are sometimes dropped in favor of other, more * specific messages. */ - abstract class NotFoundMsg(errorId: ErrorMessageID) extends Message(errorId) with + abstract class NotFoundMsg(errorId: ErrorMessageID) extends Message(errorId): def kind = "Not Found" def name: Name - abstract class PatternMatchMsg(errorId: ErrorMessageID) extends Message(errorId) with + abstract class PatternMatchMsg(errorId: ErrorMessageID) extends Message(errorId): def kind = "Pattern Match" - abstract class CyclicMsg(errorId: ErrorMessageID) extends Message(errorId) with + abstract class CyclicMsg(errorId: ErrorMessageID) extends Message(errorId): def kind = "Cyclic" - abstract class ReferenceMsg(errorId: ErrorMessageID) extends Message(errorId) with + abstract class ReferenceMsg(errorId: ErrorMessageID) extends Message(errorId): def kind = "Reference" abstract class EmptyCatchOrFinallyBlock(tryBody: untpd.Tree, errNo: ErrorMessageID)(using Context) @@ -242,7 +242,7 @@ import transform.SymUtils._ // the idea is that if the bounds are also not-subtypes of each other to report // the type mismatch on the bounds instead of the original TypeParamRefs, since // these are usually easier to analyze. - object reported extends TypeMap with + object reported extends TypeMap: def setVariance(v: Int) = variance = v val constraint = mapCtx.typerState.constraint def apply(tp: Type): Type = tp match @@ -1126,7 +1126,6 @@ import transform.SymUtils._ def msg = val expectedText = if (Tokens.isIdentifier(expected)) "an identifier" - else if expected == Tokens.INDENT then "indented definitions" else Tokens.showToken(expected) em"""${expectedText} expected, but ${foundText} found""" @@ -1190,7 +1189,7 @@ import transform.SymUtils._ |""".stripMargin } - class UnreducibleApplication(tycon: Type)(using Context) extends TypeMsg(UnreducibleApplicationID) with + class UnreducibleApplication(tycon: Type)(using Context) extends TypeMsg(UnreducibleApplicationID): def msg = em"unreducible application of higher-kinded type $tycon to wildcard arguments" def explain = em"""|An abstract type constructor cannot be applied to wildcard arguments. @@ -1662,7 +1661,7 @@ import transform.SymUtils._ def explain = "Method inlining prohibits calling superclass methods, as it may lead to confusion about which super is being called." } - class NotAPath(tp: Type, usage: String)(using Context) extends TypeMsg(NotAPathID) with + class NotAPath(tp: Type, usage: String)(using Context) extends TypeMsg(NotAPathID): def msg = em"$tp is not a valid $usage, since it is not an immutable path" def explain = i"""An immutable path is @@ -1852,7 +1851,7 @@ import transform.SymUtils._ def explain = "" } - class AlreadyDefined(name: Name, owner: Symbol, conflicting: Symbol)(using Context) extends NamingMsg(AlreadyDefinedID) with + class AlreadyDefined(name: Name, owner: Symbol, conflicting: Symbol)(using Context) extends NamingMsg(AlreadyDefinedID): private def where: String = if conflicting.effectiveOwner.is(Package) && conflicting.associatedFile != null then i" in ${conflicting.associatedFile}" diff --git a/compiler/src/dotty/tools/dotc/reporting/trace.scala b/compiler/src/dotty/tools/dotc/reporting/trace.scala index 4acd1e817d33..07a67c2c9cc2 100644 --- a/compiler/src/dotty/tools/dotc/reporting/trace.scala +++ b/compiler/src/dotty/tools/dotc/reporting/trace.scala @@ -7,11 +7,11 @@ import config.Config import config.Printers import core.Mode -object trace extends TraceSyntax with +object trace extends TraceSyntax: inline def isEnabled = Config.tracingEnabled protected val isForced = false - object force extends TraceSyntax with + object force extends TraceSyntax: inline def isEnabled: true = true protected val isForced = true end trace @@ -20,7 +20,7 @@ end trace * is false. The `trace` operation is called in various hotspots, so every tiny bit * of overhead is unacceptable: boxing, closures, additional method calls are all out. */ -trait TraceSyntax with +trait TraceSyntax: inline def isEnabled: Boolean protected val isForced: Boolean diff --git a/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala b/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala index 8b62f443cf56..e1b5abe799e1 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala @@ -28,7 +28,7 @@ import scala.PartialFunction.condOpt * for a description of the format. * TODO: Also extract type information */ -class ExtractSemanticDB extends Phase with +class ExtractSemanticDB extends Phase: import Scala3.{_, given} import Symbols.given @@ -47,7 +47,7 @@ class ExtractSemanticDB extends Phase with ExtractSemanticDB.write(unit.source, extract.occurrences.toList, extract.symbolInfos.toList) /** Extractor of symbol occurrences from trees */ - class Extractor extends TreeTraverser with + class Extractor extends TreeTraverser: private var nextLocalIdx: Int = 0 @@ -249,7 +249,7 @@ class ExtractSemanticDB extends Phase with name => locals.keys.find(local => local.isTerm && local.owner == funSym && local.name == name) .fold("")(Symbols.LocalPrefix + _) - private object PatternValDef with + private object PatternValDef: def unapply(tree: ValDef)(using Context): Option[(Tree, Tree)] = tree.rhs match @@ -583,7 +583,7 @@ class ExtractSemanticDB extends Phase with registerSymbol(vparam.symbol, symbolName(vparam.symbol), symkinds) traverse(vparam.tpt) -object ExtractSemanticDB with +object ExtractSemanticDB: import java.nio.file.Path import scala.collection.JavaConverters._ import java.nio.file.Files diff --git a/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala b/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala index 22a6e6462036..be9006592a4e 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala @@ -15,7 +15,7 @@ import java.lang.Character.{isJavaIdentifierPart, isJavaIdentifierStart} import scala.annotation.internal.sharable import scala.annotation.switch -object Scala3 with +object Scala3: import Symbols._ import core.NameOps._ @@ -25,7 +25,7 @@ object Scala3 with private val WILDCARDTypeName = nme.WILDCARD.toTypeName - enum SymbolKind derives CanEqual with + enum SymbolKind derives CanEqual: kind => case Val, Var, Setter, Abstract @@ -38,13 +38,13 @@ object Scala3 with end SymbolKind - object SymbolKind with + object SymbolKind: val ValSet = Set(Val) val VarSet = Set(Var) val emptySet = Set.empty[SymbolKind] end SymbolKind - object Symbols with + object Symbols: val RootPackage: String = "_root_/" val EmptyPackage: String = "_empty_/" @@ -126,7 +126,7 @@ object Scala3 with end SymbolOps - object LocalSymbol with + object LocalSymbol: def unapply(symbolInfo: SymbolInformation): Option[Int] = symbolInfo.symbol match case locals(ints) => @@ -234,7 +234,7 @@ object Scala3 with * * taken from https://github.com/scalameta/scalameta/blob/master/semanticdb/metap/src/main/scala/scala/meta/internal/metap/IdentifierOrdering.scala */ - private class IdentifierOrdering[T <: CharSequence] extends Ordering[T] with + private class IdentifierOrdering[T <: CharSequence] extends Ordering[T]: override def compare(o1: T, o2: T): Int = val len = math.min(o1.length(), o2.length()) diff --git a/compiler/src/dotty/tools/dotc/semanticdb/Tools.scala b/compiler/src/dotty/tools/dotc/semanticdb/Tools.scala index a6c3089bf595..ce2e943ed7a1 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/Tools.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/Tools.scala @@ -6,7 +6,7 @@ import scala.collection.JavaConverters._ import dotty.tools.dotc.util.SourceFile import dotty.tools.dotc.semanticdb.Scala3.{_, given} -object Tools with +object Tools: /** Converts a Path to a String that is URI encoded, without forcing absolute paths. */ def mkURIstring(path: Path): String = diff --git a/compiler/src/dotty/tools/dotc/transform/BetaReduce.scala b/compiler/src/dotty/tools/dotc/transform/BetaReduce.scala index 0104bbd2db11..17ce6020e2a9 100644 --- a/compiler/src/dotty/tools/dotc/transform/BetaReduce.scala +++ b/compiler/src/dotty/tools/dotc/transform/BetaReduce.scala @@ -30,7 +30,7 @@ import ast.TreeTypeMap * A typical use case is eliminating redundant closures for blackbox macros that * return context functions. See i6375.scala. */ -class BetaReduce extends MiniPhase with +class BetaReduce extends MiniPhase: import ast.tpd._ def phaseName: String = "betaReduce" @@ -44,7 +44,7 @@ class BetaReduce extends MiniPhase with app -object BetaReduce with +object BetaReduce: import ast.tpd._ /** Beta-reduces a call to `fn` with arguments `argSyms` or returns `tree` */ diff --git a/compiler/src/dotty/tools/dotc/transform/ContextFunctionResults.scala b/compiler/src/dotty/tools/dotc/transform/ContextFunctionResults.scala index 2bfd2d7985a5..ee56767054fd 100644 --- a/compiler/src/dotty/tools/dotc/transform/ContextFunctionResults.scala +++ b/compiler/src/dotty/tools/dotc/transform/ContextFunctionResults.scala @@ -9,7 +9,7 @@ import ast.untpd import ast.tpd._ import config.Config -object ContextFunctionResults with +object ContextFunctionResults: /** Annotate methods that have context function result types directly matched by context * closures on their right-hand side. Parameters to such closures will be integrated diff --git a/compiler/src/dotty/tools/dotc/transform/CountOuterAccesses.scala b/compiler/src/dotty/tools/dotc/transform/CountOuterAccesses.scala index 6e28877fcb1e..27a7907b266e 100644 --- a/compiler/src/dotty/tools/dotc/transform/CountOuterAccesses.scala +++ b/compiler/src/dotty/tools/dotc/transform/CountOuterAccesses.scala @@ -13,7 +13,7 @@ import ExplicitOuter.isOuterParamAccessor import collection.mutable -object CountOuterAccesses with +object CountOuterAccesses: val name: String = "countOuterAccesses" /** Characterizes outer accessors and outer fields that can be dropped @@ -32,7 +32,7 @@ object CountOuterAccesses with * is collected in `outerAccessCount` and used in the subsequent * DropOuterAccessors phase */ -class CountOuterAccesses extends MiniPhase with +class CountOuterAccesses extends MiniPhase: thisPhase => import tpd._ diff --git a/compiler/src/dotty/tools/dotc/transform/DropOuterAccessors.scala b/compiler/src/dotty/tools/dotc/transform/DropOuterAccessors.scala index 75798998fcb0..c6b3785e99ed 100644 --- a/compiler/src/dotty/tools/dotc/transform/DropOuterAccessors.scala +++ b/compiler/src/dotty/tools/dotc/transform/DropOuterAccessors.scala @@ -16,14 +16,14 @@ import CountOuterAccesses.mightBeDropped import collection.mutable import annotation.threadUnsafe -object DropOuterAccessors with +object DropOuterAccessors: val name: String = "dropOuterAccessors" /** Drops unused outer accessors of inner classes that are visible only in one * toplevel class. For other classes, we can't tell whether an outer accessor * is used or not. It could for instance be used in a type test in some other source. */ -class DropOuterAccessors extends MiniPhase with IdentityDenotTransformer with +class DropOuterAccessors extends MiniPhase with IdentityDenotTransformer: thisPhase => import tpd._ diff --git a/compiler/src/dotty/tools/dotc/transform/Erasure.scala b/compiler/src/dotty/tools/dotc/transform/Erasure.scala index 4d1259a61fdd..27c39a79cf14 100644 --- a/compiler/src/dotty/tools/dotc/transform/Erasure.scala +++ b/compiler/src/dotty/tools/dotc/transform/Erasure.scala @@ -208,7 +208,7 @@ object Erasure { else mt case _ => mt - object Boxing with + object Boxing: def isUnbox(sym: Symbol)(using Context): Boolean = sym.name == nme.unbox && sym.owner.linkedClass.isPrimitiveValueClass diff --git a/compiler/src/dotty/tools/dotc/transform/ExpandSAMs.scala b/compiler/src/dotty/tools/dotc/transform/ExpandSAMs.scala index 4a0fae1c0d54..c0ea4adee353 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExpandSAMs.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExpandSAMs.scala @@ -22,7 +22,7 @@ import dotty.tools.dotc.util.Spans.Span * * However, implicit function types do not count as SAM types. */ -object ExpandSAMs with +object ExpandSAMs: val name: String = "expandSAMs" /** Is the SAMType `cls` also a SAM under the rules of the platform? */ @@ -34,7 +34,7 @@ object ExpandSAMs with case cls: ClassSymbol => !isPlatformSam(cls) || cls == defn.PartialFunctionClass case _ => false -class ExpandSAMs extends MiniPhase with +class ExpandSAMs extends MiniPhase: import ast.tpd._ override def phaseName: String = ExpandSAMs.name diff --git a/compiler/src/dotty/tools/dotc/transform/InlinePatterns.scala b/compiler/src/dotty/tools/dotc/transform/InlinePatterns.scala index f8b5445981c0..fdef553a835d 100644 --- a/compiler/src/dotty/tools/dotc/transform/InlinePatterns.scala +++ b/compiler/src/dotty/tools/dotc/transform/InlinePatterns.scala @@ -26,7 +26,7 @@ import ast.TreeTypeMap * * This removes placeholders added by inline `unapply`/`unapplySeq` patterns. */ -class InlinePatterns extends MiniPhase with +class InlinePatterns extends MiniPhase: import ast.tpd._ def phaseName: String = "inlinePatterns" @@ -46,7 +46,7 @@ class InlinePatterns extends MiniPhase with app else app - private object App with + private object App: def unapply(app: Tree): (Tree, List[List[Tree]]) = app match case Apply(App(fn, argss), args) => (fn, argss :+ args) diff --git a/compiler/src/dotty/tools/dotc/transform/LetOverApply.scala b/compiler/src/dotty/tools/dotc/transform/LetOverApply.scala index 808adc5ba7e2..cd61c0f5ac82 100644 --- a/compiler/src/dotty/tools/dotc/transform/LetOverApply.scala +++ b/compiler/src/dotty/tools/dotc/transform/LetOverApply.scala @@ -12,7 +12,7 @@ import ast.Trees._ * but leave closures alone. This is necessary to be able to * collapse applies of IFTs (this is done in Erasure). */ -class LetOverApply extends MiniPhase with +class LetOverApply extends MiniPhase: import ast.tpd._ override def phaseName: String = "letOverApply" diff --git a/compiler/src/dotty/tools/dotc/transform/LiftTry.scala b/compiler/src/dotty/tools/dotc/transform/LiftTry.scala index 167848488cb1..e5e234b8fe8e 100644 --- a/compiler/src/dotty/tools/dotc/transform/LiftTry.scala +++ b/compiler/src/dotty/tools/dotc/transform/LiftTry.scala @@ -78,5 +78,5 @@ class LiftTry extends MiniPhase with IdentityDenotTransformer { thisPhase => } else tree } -object LiftTry with +object LiftTry: val name = "liftTry" diff --git a/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala b/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala index 0e192279eb48..028516f1ca07 100644 --- a/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala +++ b/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala @@ -31,7 +31,7 @@ import config.Printers.typr * * The aim of this transformation is to avoid redundant parameter accessor fields. */ -class ParamForwarding extends MiniPhase with IdentityDenotTransformer with +class ParamForwarding extends MiniPhase with IdentityDenotTransformer: import ast.tpd._ private def thisPhase: ParamForwarding = this diff --git a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala index d086ee1ef0cd..3bbcdef68932 100644 --- a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala +++ b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala @@ -22,7 +22,7 @@ import ast.tpd.Literal import language.implicitConversions import scala.annotation.tailrec -object SymUtils with +object SymUtils: extension (self: Symbol) diff --git a/compiler/src/dotty/tools/dotc/transform/UncacheGivenAliases.scala b/compiler/src/dotty/tools/dotc/transform/UncacheGivenAliases.scala index 9bfbd6b0925a..958fce04da77 100644 --- a/compiler/src/dotty/tools/dotc/transform/UncacheGivenAliases.scala +++ b/compiler/src/dotty/tools/dotc/transform/UncacheGivenAliases.scala @@ -13,7 +13,7 @@ import core.Decorators._ import core.TypeErasure.erasure import ast.tpd -object UncacheGivenAliases with +object UncacheGivenAliases: val name: String = "uncacheGivenAliases" /** This phase optimizes alias givens represented as lazy vals to be uncached @@ -24,7 +24,7 @@ object UncacheGivenAliases with * this.y * y */ -class UncacheGivenAliases extends MiniPhase with IdentityDenotTransformer with +class UncacheGivenAliases extends MiniPhase with IdentityDenotTransformer: thisPhase => import tpd._ diff --git a/compiler/src/dotty/tools/dotc/typer/ConstFold.scala b/compiler/src/dotty/tools/dotc/typer/ConstFold.scala index d2c373299bee..0bf1e4a076ea 100644 --- a/compiler/src/dotty/tools/dotc/typer/ConstFold.scala +++ b/compiler/src/dotty/tools/dotc/typer/ConstFold.scala @@ -14,7 +14,7 @@ import StdNames._ import Contexts._ import transform.TypeUtils._ -object ConstFold with +object ConstFold: import tpd._ diff --git a/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala b/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala index 13b2c75146e2..c4936b5a3a9e 100644 --- a/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala +++ b/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala @@ -155,7 +155,7 @@ class LiftComplex extends Lifter { } object LiftComplex extends LiftComplex -object LiftErased extends LiftComplex with +object LiftErased extends LiftComplex: override def isErased = true /** Lift all impure or complex arguments to `def`s */ diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index 30cc9b00b38b..4e48b8b93cf3 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -40,7 +40,7 @@ import scala.annotation.internal.sharable import scala.annotation.threadUnsafe /** Implicit resolution */ -object Implicits with +object Implicits: import tpd._ /** An implicit definition `implicitRef` that is visible under a different name, `alias`. @@ -517,14 +517,14 @@ object Implicits with } /** A search failure type for attempted ill-typed extension method calls */ - class FailedExtension(extApp: Tree, val expectedType: Type, val whyFailed: Message) extends SearchFailureType with + class FailedExtension(extApp: Tree, val expectedType: Type, val whyFailed: Message) extends SearchFailureType: def argument = EmptyTree def explanation(using Context) = em"$extApp does not $qualify" /** A search failure type for aborted searches of extension methods, typically * because of a cyclic reference or similar. */ - class NestedFailure(_msg: Message, val expectedType: Type) extends SearchFailureType with + class NestedFailure(_msg: Message, val expectedType: Type) extends SearchFailureType: def argument = EmptyTree override def msg(using Context) = _msg def explanation(using Context) = msg.toString @@ -534,7 +534,8 @@ end Implicits import Implicits._ /** Info relating to implicits that is kept for one run */ -trait ImplicitRunInfo with self: Run => +trait ImplicitRunInfo: + self: Run => private val implicitScopeCache = util.EqHashMap[Type, OfTypeImplicits]() @@ -553,7 +554,7 @@ trait ImplicitRunInfo with self: Run => private def computeIScope(rootTp: Type): OfTypeImplicits = - object collectParts extends TypeTraverser with + object collectParts extends TypeTraverser: private var provisional: Boolean = _ private var parts: mutable.LinkedHashSet[Type] = _ @@ -756,7 +757,7 @@ trait ImplicitRunInfo with self: Run => end ImplicitRunInfo /** The implicit resolution part of type checking */ -trait Implicits with +trait Implicits: self: Typer => import tpd._ @@ -930,7 +931,7 @@ trait Implicits with implicits.println(i"CanEqual witness found for $ltp / $rtp: $res: ${res.tpe}") } - object hasSkolem extends TreeAccumulator[Boolean] with + object hasSkolem extends TreeAccumulator[Boolean]: def apply(x: Boolean, tree: Tree)(using Context): Boolean = x || { tree match @@ -1075,7 +1076,7 @@ trait Implicits with } /** An implicit search; parameters as in `inferImplicit` */ - class ImplicitSearch(protected val pt: Type, protected val argument: Tree, span: Span)(using Context) with + class ImplicitSearch(protected val pt: Type, protected val argument: Tree, span: Span)(using Context): assert(argument.isEmpty || argument.tpe.isValueType || argument.tpe.isInstanceOf[ExprType], em"found: $argument: ${argument.tpe}, expected: $pt") @@ -1442,7 +1443,7 @@ end Implicits * recursive references and emit a complete implicit dictionary when the outermost search * is complete. */ -abstract class SearchHistory with +abstract class SearchHistory: val root: SearchRoot /** Does this search history contain any by name implicit arguments. */ val byname: Boolean @@ -1470,7 +1471,7 @@ abstract class SearchHistory with override def toString: String = s"SearchHistory(open = $openSearchPairs, byname = $byname)" end SearchHistory -case class OpenSearch(cand: Candidate, pt: Type, outer: SearchHistory)(using Context) extends SearchHistory with +case class OpenSearch(cand: Candidate, pt: Type, outer: SearchHistory)(using Context) extends SearchHistory: val root = outer.root val byname = outer.byname || pt.isByName def openSearchPairs = (cand, pt) :: outer.openSearchPairs @@ -1488,7 +1489,7 @@ end OpenSearch /** * The the state corresponding to the outermost context of an implicit searcch. */ -final class SearchRoot extends SearchHistory with +final class SearchRoot extends SearchHistory: val root = this val byname = false def openSearchPairs = Nil @@ -1656,7 +1657,7 @@ final class SearchRoot extends SearchHistory with end SearchRoot /** A set of term references where equality is =:= */ -sealed class TermRefSet(using Context) with +sealed class TermRefSet(using Context): private val elems = new java.util.LinkedHashMap[TermSymbol, Type | List[Type]] def isEmpty = elems.size == 0 @@ -1691,7 +1692,7 @@ sealed class TermRefSet(using Context) with override def toString = showAsList.toString -object TermRefSet with +object TermRefSet: @sharable val empty = new TermRefSet(using NoContext): override def += (ref: TermRef): Unit = throw UnsupportedOperationException("+=") diff --git a/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala b/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala index 1dbf151a0b5e..4c3e8b0980dd 100644 --- a/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala +++ b/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala @@ -18,7 +18,8 @@ import scala.util.control.NonFatal /** This trait defines the method `importSuggestionAddendum` that adds an addendum * to error messages suggesting additional imports. */ -trait ImportSuggestions with this: Typer => +trait ImportSuggestions: + this: Typer => /** The maximal number of suggested imports to make */ inline val MaxSuggestions = 10 diff --git a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala index 61a02a01e518..1392ed688959 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala @@ -619,6 +619,6 @@ trait Inferencing { this: Typer => val flipBottom: Value = new Value(_ => true, IfBottom.flip) } -enum IfBottom with +enum IfBottom: case ok, fail, flip diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 184744c3d47a..79e1b739b542 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -276,7 +276,7 @@ object Inliner { object Intrinsics { import dotty.tools.dotc.reporting.Diagnostic.Error - private enum ErrorKind with + private enum ErrorKind: case Parser, Typer private def compileForErrors(tree: Tree, stopAfterParser: Boolean)(using Context): List[(ErrorKind, Error)] = diff --git a/compiler/src/dotty/tools/dotc/typer/Nullables.scala b/compiler/src/dotty/tools/dotc/typer/Nullables.scala index a57a97ea3276..782b156e32a4 100644 --- a/compiler/src/dotty/tools/dotc/typer/Nullables.scala +++ b/compiler/src/dotty/tools/dotc/typer/Nullables.scala @@ -17,13 +17,13 @@ import ast.{tpd, untpd} import ast.Trees.mods /** Operations for implementing a flow analysis for nullability */ -object Nullables with +object Nullables: import ast.tpd._ /** A set of val or var references that are known to be not null, plus a set of * variable references that are not known (anymore) to be not null */ - case class NotNullInfo(asserted: Set[TermRef], retracted: Set[TermRef]) with + case class NotNullInfo(asserted: Set[TermRef], retracted: Set[TermRef]): assert((asserted & retracted).isEmpty) def isEmpty = this eq NotNullInfo.empty @@ -44,7 +44,7 @@ object Nullables with def alt(that: NotNullInfo): NotNullInfo = NotNullInfo(this.asserted.intersect(that.asserted), this.retracted.union(that.retracted)) - object NotNullInfo with + object NotNullInfo: val empty = new NotNullInfo(Set(), Set()) def apply(asserted: Set[TermRef], retracted: Set[TermRef]): NotNullInfo = if asserted.isEmpty && retracted.isEmpty then empty @@ -52,10 +52,10 @@ object Nullables with end NotNullInfo /** A pair of not-null sets, depending on whether a condition is `true` or `false` */ - case class NotNullConditional(ifTrue: Set[TermRef], ifFalse: Set[TermRef]) with + case class NotNullConditional(ifTrue: Set[TermRef], ifFalse: Set[TermRef]): def isEmpty = this eq NotNullConditional.empty - object NotNullConditional with + object NotNullConditional: val empty = new NotNullConditional(Set(), Set()) def apply(ifTrue: Set[TermRef], ifFalse: Set[TermRef]): NotNullConditional = if ifTrue.isEmpty && ifFalse.isEmpty then empty @@ -73,7 +73,7 @@ object Nullables with private[typer] val NNInfo = Property.StickyKey[NotNullInfo] /** An extractor for null comparisons */ - object CompareNull with + object CompareNull: /** Matches one of * @@ -98,7 +98,7 @@ object Nullables with end CompareNull /** An extractor for null-trackable references */ - object TrackedRef with + object TrackedRef: def unapply(tree: Tree)(using Context): Option[TermRef] = tree.typeOpt match case ref: TermRef if isTracked(ref) => Some(ref) case _ => None @@ -375,7 +375,7 @@ object Nullables with def assignmentSpans(using Context): Map[Int, List[Span]] = import ast.untpd._ - object populate extends UntypedTreeTraverser with + object populate extends UntypedTreeTraverser: /** The name offsets of variables that are tracked */ var tracked: Map[Int, List[Span]] = Map.empty @@ -482,7 +482,7 @@ object Nullables with if mt.paramInfos.exists(_.isInstanceOf[ExprType]) && !fn.symbol.is(Inline) => app match case Apply(fn, args) => - object dropNotNull extends TreeMap with + object dropNotNull extends TreeMap: var dropped: Boolean = false override def transform(t: Tree)(using Context) = t match case AssertNotNull(t0) if t0.symbol.is(Mutable) => @@ -497,7 +497,7 @@ object Nullables with t case _ => super.transform(t) - object retyper extends ReTyper with + object retyper extends ReTyper: override def typedUnadapted(t: untpd.Tree, pt: Type, locked: TypeVars)(using Context): Tree = t match case t: untpd.ValDef if !t.symbol.is(Lazy) => super.typedUnadapted(t, pt, locked) case t: untpd.MemberDef => promote(t) diff --git a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala index 4172be7366ae..1da24e4f8146 100644 --- a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -120,7 +120,7 @@ object ProtoTypes { } /** A class marking ignored prototypes that can be revealed by `deepenProto` */ - abstract case class IgnoredProto(ignored: Type) extends CachedGroundType with MatchAlways with + abstract case class IgnoredProto(ignored: Type) extends CachedGroundType with MatchAlways: override def revealIgnored = ignored override def deepenProto(using Context): Type = ignored @@ -135,7 +135,7 @@ object ProtoTypes { final class CachedIgnoredProto(ignored: Type) extends IgnoredProto(ignored) - object IgnoredProto with + object IgnoredProto: def apply(ignored: Type)(using Context): IgnoredProto = ignored match case ignored: IgnoredProto => ignored case _ => unique(CachedIgnoredProto(ignored)) diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index 0f5e437bca5f..fa00cc62be71 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -1023,7 +1023,7 @@ object RefChecks { /** Verify that references in the user-defined `@implicitNotFound` message are valid. * (i.e. they refer to a type variable that really occurs in the signature of the annotated symbol.) */ - private object checkImplicitNotFoundAnnotation with + private object checkImplicitNotFoundAnnotation: /** Warns if the class or trait has an @implicitNotFound annotation * with invalid type variable references. */ @@ -1040,7 +1040,7 @@ object RefChecks { if param.isTerm do checkReferences(param.denot) - private object PositionedStringLiteralArgument with + private object PositionedStringLiteralArgument: def unapply(tree: Tree): Option[(String, Span)] = tree match { case l@Literal(Constant(s: String)) => Some((s, l.span)) case NamedArg(_, l@Literal(Constant(s: String))) => Some((s, l.span)) diff --git a/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala b/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala index 488c5bc51764..445c130e50fb 100644 --- a/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala @@ -18,7 +18,7 @@ import util.Property import annotation.{tailrec, constructorOnly} /** Synthesize terms for special classes */ -class Synthesizer(typer: Typer)(using @constructorOnly c: Context) with +class Synthesizer(typer: Typer)(using @constructorOnly c: Context): import ast.tpd._ /** Handlers to synthesize implicits for special types */ diff --git a/compiler/src/dotty/tools/dotc/util/CharBuffer.scala b/compiler/src/dotty/tools/dotc/util/CharBuffer.scala index aedacceb2185..ad51702ca7f1 100644 --- a/compiler/src/dotty/tools/dotc/util/CharBuffer.scala +++ b/compiler/src/dotty/tools/dotc/util/CharBuffer.scala @@ -5,7 +5,7 @@ package util /** A character buffer that exposes the internal array for reading. * That way we can avoid copying when converting to names. */ -class CharBuffer(initialSize: Int = 1024) with +class CharBuffer(initialSize: Int = 1024): private var cs: Array[Char] = new Array[Char](initialSize) private var len: Int = 0 diff --git a/compiler/src/dotty/tools/dotc/util/GenericHashMap.scala b/compiler/src/dotty/tools/dotc/util/GenericHashMap.scala index 2ce8aecf5770..f2a3f012f76c 100644 --- a/compiler/src/dotty/tools/dotc/util/GenericHashMap.scala +++ b/compiler/src/dotty/tools/dotc/util/GenericHashMap.scala @@ -1,7 +1,7 @@ package dotty.tools package dotc.util -object GenericHashMap with +object GenericHashMap: /** The number of elements up to which dense packing is used. * If the number of elements reaches `DenseLimit` a hash table is used instead @@ -163,7 +163,7 @@ abstract class GenericHashMap[Key, Value] allocate(newLength) copyFrom(oldTable) - private abstract class EntryIterator[T] extends Iterator[T] with + private abstract class EntryIterator[T] extends Iterator[T]: def entry(idx: Int): T private var idx = 0 def hasNext = diff --git a/compiler/src/dotty/tools/dotc/util/HashSet.scala b/compiler/src/dotty/tools/dotc/util/HashSet.scala index 13f046414348..e7406f9ab094 100644 --- a/compiler/src/dotty/tools/dotc/util/HashSet.scala +++ b/compiler/src/dotty/tools/dotc/util/HashSet.scala @@ -1,6 +1,6 @@ package dotty.tools.dotc.util -object HashSet with +object HashSet: /** The number of elements up to which dense packing is used. * If the number of elements reaches `DenseLimit` a hash table is used instead @@ -159,7 +159,7 @@ class HashSet[T](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends Mu allocate(newLength) copyFrom(oldTable) - abstract class EntryIterator extends Iterator[T] with + abstract class EntryIterator extends Iterator[T]: def entry(idx: Int): T private var idx = 0 def hasNext = diff --git a/compiler/src/dotty/tools/dotc/util/LinearMap.scala b/compiler/src/dotty/tools/dotc/util/LinearMap.scala index 4f3137e7e250..1e5754c34f3e 100644 --- a/compiler/src/dotty/tools/dotc/util/LinearMap.scala +++ b/compiler/src/dotty/tools/dotc/util/LinearMap.scala @@ -10,7 +10,7 @@ import collection.immutable opaque type LinearMap[K <: AnyRef, V >: Null <: AnyRef] = immutable.Map[K, V] | HashMap[K, V] -object LinearMap with +object LinearMap: def empty[K <: AnyRef, V >: Null <: AnyRef]: LinearMap[K, V] = immutable.Map.empty[K, V] diff --git a/compiler/src/dotty/tools/dotc/util/LinearSet.scala b/compiler/src/dotty/tools/dotc/util/LinearSet.scala index e95b42091b8b..80507ef8bedb 100644 --- a/compiler/src/dotty/tools/dotc/util/LinearSet.scala +++ b/compiler/src/dotty/tools/dotc/util/LinearSet.scala @@ -8,7 +8,7 @@ import collection.immutable opaque type LinearSet[Elem >: Null <: AnyRef] = immutable.Set[Elem] | HashSet[Elem] -object LinearSet with +object LinearSet: def empty[Elem >: Null <: AnyRef]: LinearSet[Elem] = immutable.Set.empty[Elem] diff --git a/compiler/src/dotty/tools/dotc/util/MutableMap.scala b/compiler/src/dotty/tools/dotc/util/MutableMap.scala index a5157c91b25e..ba912a312aea 100644 --- a/compiler/src/dotty/tools/dotc/util/MutableMap.scala +++ b/compiler/src/dotty/tools/dotc/util/MutableMap.scala @@ -3,7 +3,7 @@ package dotc.util /** A common class for lightweight mutable maps. */ -abstract class MutableMap[Key, Value] extends ReadOnlyMap[Key, Value] with +abstract class MutableMap[Key, Value] extends ReadOnlyMap[Key, Value]: def update(k: Key, v: Value): Unit diff --git a/compiler/src/dotty/tools/dotc/util/MutableSet.scala b/compiler/src/dotty/tools/dotc/util/MutableSet.scala index 4c0bd09b7d63..bedb079f18ca 100644 --- a/compiler/src/dotty/tools/dotc/util/MutableSet.scala +++ b/compiler/src/dotty/tools/dotc/util/MutableSet.scala @@ -2,7 +2,7 @@ package dotty.tools.dotc.util /** A common class for lightweight mutable sets. */ -abstract class MutableSet[T] extends ReadOnlySet[T] with +abstract class MutableSet[T] extends ReadOnlySet[T]: /** Add element `x` to the set */ def +=(x: T): Unit diff --git a/compiler/src/dotty/tools/dotc/util/PerfectHashing.scala b/compiler/src/dotty/tools/dotc/util/PerfectHashing.scala index 012bbc5bb044..fca790837959 100644 --- a/compiler/src/dotty/tools/dotc/util/PerfectHashing.scala +++ b/compiler/src/dotty/tools/dotc/util/PerfectHashing.scala @@ -1,6 +1,6 @@ package dotty.tools.dotc.util -object PerfectHashing with +object PerfectHashing: /** The number of elements up to which dense packing is used. * If the number of elements reaches `DenseLimit` a hash table is used instead @@ -19,7 +19,7 @@ object PerfectHashing with * However, a table of size up to DenseLimit will be re-sized only * once the number of elements reaches the table's size. */ -class PerfectHashing[Key](initialCapacity: Int = 8, capacityMultiple: Int = 2) with +class PerfectHashing[Key](initialCapacity: Int = 8, capacityMultiple: Int = 2): import PerfectHashing.DenseLimit private var used: Int = _ diff --git a/compiler/src/dotty/tools/dotc/util/ReadOnlyMap.scala b/compiler/src/dotty/tools/dotc/util/ReadOnlyMap.scala index 950d38eb7bf2..020303c18bc2 100644 --- a/compiler/src/dotty/tools/dotc/util/ReadOnlyMap.scala +++ b/compiler/src/dotty/tools/dotc/util/ReadOnlyMap.scala @@ -3,7 +3,7 @@ package dotc.util /** A class for the reading part of mutable or immutable maps. */ -abstract class ReadOnlyMap[Key, Value] with +abstract class ReadOnlyMap[Key, Value]: def lookup(x: Key): Value | Null diff --git a/compiler/src/dotty/tools/dotc/util/ReadOnlySet.scala b/compiler/src/dotty/tools/dotc/util/ReadOnlySet.scala index 570bd416c4f1..4826d02743a9 100644 --- a/compiler/src/dotty/tools/dotc/util/ReadOnlySet.scala +++ b/compiler/src/dotty/tools/dotc/util/ReadOnlySet.scala @@ -2,7 +2,7 @@ package dotty.tools.dotc.util /** A class for the readonly part of mutable sets. */ -abstract class ReadOnlySet[T] with +abstract class ReadOnlySet[T]: /** The entry in the set such that `isEqual(x, entry)`, or else `null`. */ def lookup(x: T): T | Null @@ -19,6 +19,6 @@ abstract class ReadOnlySet[T] with def isEmpty = size == 0 -object ReadOnlySet with +object ReadOnlySet: def empty[T]: ReadOnlySet[T] = HashSet[T](4) diff --git a/compiler/src/dotty/tools/dotc/util/SourcePosition.scala b/compiler/src/dotty/tools/dotc/util/SourcePosition.scala index e67db3e8c147..160631bc41b0 100644 --- a/compiler/src/dotty/tools/dotc/util/SourcePosition.scala +++ b/compiler/src/dotty/tools/dotc/util/SourcePosition.scala @@ -91,7 +91,7 @@ extends SrcPos, interfaces.SourcePosition, Showable { } /** Things that can produce a source position and a span */ -trait SrcPos with +trait SrcPos: def sourcePos(using ctx: Context): SourcePosition def span: Span def startPos(using ctx: Context): SourcePosition = sourcePos.startPos diff --git a/compiler/src/dotty/tools/dotc/util/StackTraceOps.scala b/compiler/src/dotty/tools/dotc/util/StackTraceOps.scala index 035a9bc02b4c..071fc22afa3d 100644 --- a/compiler/src/dotty/tools/dotc/util/StackTraceOps.scala +++ b/compiler/src/dotty/tools/dotc/util/StackTraceOps.scala @@ -16,7 +16,7 @@ import collection.mutable, mutable.ListBuffer import scala.util.chaining.given import java.lang.System.lineSeparator -object StackTraceOps with +object StackTraceOps: extension (t: Throwable) diff --git a/compiler/src/dotty/tools/repl/ReplCompillationUnit.scala b/compiler/src/dotty/tools/repl/ReplCompillationUnit.scala index 7842bdf8a3a3..d3f2cee7e207 100644 --- a/compiler/src/dotty/tools/repl/ReplCompillationUnit.scala +++ b/compiler/src/dotty/tools/repl/ReplCompillationUnit.scala @@ -4,5 +4,5 @@ import dotty.tools.dotc.CompilationUnit import dotty.tools.dotc.util.SourceFile -class ReplCompilationUnit(source: SourceFile) extends CompilationUnit(source) with +class ReplCompilationUnit(source: SourceFile) extends CompilationUnit(source): override def isSuspendable: Boolean = false diff --git a/compiler/src/dotty/tools/scripting/Main.scala b/compiler/src/dotty/tools/scripting/Main.scala index 2d9361835a9d..f820421860a6 100644 --- a/compiler/src/dotty/tools/scripting/Main.scala +++ b/compiler/src/dotty/tools/scripting/Main.scala @@ -3,7 +3,7 @@ package dotty.tools.scripting import java.io.File /** Main entry point to the Scripting execution engine */ -object Main with +object Main: /** All arguments before -script are compiler arguments. All arguments afterwards are script arguments.*/ def distinguishArgs(args: Array[String]): (Array[String], File, Array[String]) = diff --git a/compiler/src/dotty/tools/scripting/ScriptingDriver.scala b/compiler/src/dotty/tools/scripting/ScriptingDriver.scala index 40a92dd02d05..d5fad4ef520a 100644 --- a/compiler/src/dotty/tools/scripting/ScriptingDriver.scala +++ b/compiler/src/dotty/tools/scripting/ScriptingDriver.scala @@ -16,7 +16,7 @@ import dotty.tools.dotc.config.Settings.Setting._ import sys.process._ -class ScriptingDriver(compilerArgs: Array[String], scriptFile: File, scriptArgs: Array[String]) extends Driver with +class ScriptingDriver(compilerArgs: Array[String], scriptFile: File, scriptArgs: Array[String]) extends Driver: def compileAndRun(): Unit = val outDir = Files.createTempDirectory("scala3-scripting") val (toCompile, rootCtx) = setup(compilerArgs :+ scriptFile.getAbsolutePath, initCtx.fresh) diff --git a/compiler/test/dotty/tools/AnnotationsTests.scala b/compiler/test/dotty/tools/AnnotationsTests.scala index b54bf4a7f57a..a197ca4bc94e 100644 --- a/compiler/test/dotty/tools/AnnotationsTests.scala +++ b/compiler/test/dotty/tools/AnnotationsTests.scala @@ -14,7 +14,7 @@ import dotc.core.Symbols._ import java.io.File import java.nio.file._ -class AnnotationsTest with +class AnnotationsTest: @Test def annotTreeNotErased: Unit = withJavaCompiled( diff --git a/compiler/test/dotty/tools/SignatureTest.scala b/compiler/test/dotty/tools/SignatureTest.scala index 65a8cdee8ea1..43d517417108 100644 --- a/compiler/test/dotty/tools/SignatureTest.scala +++ b/compiler/test/dotty/tools/SignatureTest.scala @@ -14,7 +14,7 @@ import dotc.core.Symbols._ import java.io.File import java.nio.file._ -class SignatureTest with +class SignatureTest: @Test def signatureCaching: Unit = inCompilerContext(TestConfiguration.basicClasspath, separateRun = true, "case class Foo(value: Unit)") { val (ref, refSig) = atPhase(erasurePhase.next) { diff --git a/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala b/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala index 46d3718cd416..829bc2607feb 100644 --- a/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala +++ b/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala @@ -411,7 +411,7 @@ class InlineBytecodeTests extends DottyBytecodeTest { } @Test def i6375 = { - val source = """class Test with + val source = """class Test: | given Int = 0 | def f(): Int ?=> Boolean = true : (Int ?=> Boolean) | transparent inline def g(): Int ?=> Boolean = true @@ -440,7 +440,7 @@ class InlineBytecodeTests extends DottyBytecodeTest { } @Test def i6800a = { - val source = """class Foo with + val source = """class Foo: | inline def inlined(f: => Unit): Unit = f | def test: Unit = inlined { println("") } """.stripMargin @@ -459,7 +459,7 @@ class InlineBytecodeTests extends DottyBytecodeTest { } @Test def i6800b = { - val source = """class Foo with + val source = """class Foo: | inline def printIfZero(x: Int): Unit = inline x match | case 0 => println("zero") | case _ => () @@ -485,7 +485,7 @@ class InlineBytecodeTests extends DottyBytecodeTest { @Test def i9246 = { - val source = """class Foo with + val source = """class Foo: | inline def check(v:Double): Unit = if(v==0) throw new Exception() | inline def divide(v: Double, d: Double): Double = { check(d); v / d } | def test = divide(10,2) @@ -504,7 +504,7 @@ class InlineBytecodeTests extends DottyBytecodeTest { } @Test def finalVals = { - val source = """class Test with + val source = """class Test: | final val a = 1 // should be inlined but not erased | inline val b = 2 // should be inlined and erased | def test: Int = a + b @@ -527,7 +527,7 @@ class InlineBytecodeTests extends DottyBytecodeTest { @Test def i9466 = { - val source = """class Test with + val source = """class Test: | inline def i(inline f: Int => Boolean): String = | if f(34) then "a" | else "b" @@ -553,7 +553,7 @@ class InlineBytecodeTests extends DottyBytecodeTest { } @Test def beta_reduce_under_block = { - val source = """class Test with + val source = """class Test: | def test = | { | val a = 3 diff --git a/compiler/test/dotty/tools/dotc/SettingsTests.scala b/compiler/test/dotty/tools/dotc/SettingsTests.scala index e3875fdb1656..dc1308ce6cb4 100644 --- a/compiler/test/dotty/tools/dotc/SettingsTests.scala +++ b/compiler/test/dotty/tools/dotc/SettingsTests.scala @@ -41,7 +41,7 @@ class SettingsTests { assertEquals(1, reporter.errorCount) @Test def acceptUnconstrained: Unit = - object Settings extends SettingGroup with + object Settings extends SettingGroup: val foo = StringSetting("-foo", "foo", "Foo", "a") val bar = IntSetting("-bar", "Bar", 0) @@ -54,7 +54,7 @@ class SettingsTests { } @Test def validateChoices: Unit = - object Settings extends SettingGroup with + object Settings extends SettingGroup: val foo = ChoiceSetting("-foo", "foo", "Foo", List("a", "b"), "a") val bar = IntChoiceSetting("-bar", "Bar", List(0, 1, 2), 0) val baz = IntChoiceSetting("-baz", "Baz", 0 to 10, 10) diff --git a/compiler/test/dotty/tools/dotc/config/CommandLineParserTest.scala b/compiler/test/dotty/tools/dotc/config/CommandLineParserTest.scala index 35d2e50d422f..a6bd651c6365 100644 --- a/compiler/test/dotty/tools/dotc/config/CommandLineParserTest.scala +++ b/compiler/test/dotty/tools/dotc/config/CommandLineParserTest.scala @@ -4,7 +4,7 @@ package dotty.tools.dotc.config import org.junit.Assert.{assertEquals, assertTrue} import org.junit.Test -class CommandLineParserTest with +class CommandLineParserTest: import CommandLineParser.{tokenize, ParseException} private def check(tokens: String*)(input: String): Unit = assertEquals(tokens, tokenize(input)) diff --git a/compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala b/compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala index 39aeaec3c51f..a18f96dfd35b 100644 --- a/compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala +++ b/compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala @@ -7,10 +7,10 @@ import Settings._ import org.junit.Test import org.junit.Assert._ -class ScalaSettingsTests with +class ScalaSettingsTests: @Test def `A setting with aliases is accepted`: Unit = - class MySettings extends SettingGroup with + class MySettings extends SettingGroup: val classpath: Setting[String] = PathSetting("-classpath", "Specify where to find user class files.", ".", aliases = List("--class-path", "-cp")) val settings = MySettings() val args = tokenize("-cp path/to/classes1:other/path/to/classes2") @@ -23,7 +23,7 @@ class ScalaSettingsTests with assertTrue("wrong classpath", classpath == "path/to/classes1:other/path/to/classes2") @Test def `A multistring setting is multivalued`: Unit = - class SUT extends SettingGroup with + class SUT extends SettingGroup: val language: Setting[List[String]] = MultiStringSetting("-language", "feature", "Enable one or more language features.") val sut = SUT() val args = tokenize("-language:implicitConversions,dynamics") @@ -37,7 +37,7 @@ class ScalaSettingsTests with assertTrue("Has the feature", set.contains("dynamics")) @Test def `t9719 Apply -language more than once`: Unit = - class SUT extends SettingGroup with + class SUT extends SettingGroup: val language: Setting[List[String]] = MultiStringSetting("-language", "feature", "Enable one or more language features.") val sut = SUT() val args = tokenize("-language:implicitConversions -language:dynamics") @@ -51,7 +51,7 @@ class ScalaSettingsTests with assertTrue("Has the feature", set.contains("dynamics")) @Test def `Warn if multistring element is supplied multiply`: Unit = - class SUT extends SettingGroup with + class SUT extends SettingGroup: val language: Setting[List[String]] = MultiStringSetting("-language", "feature", "Enable one or more language features.") val sut = SUT() val args = tokenize("-language:dynamics -language:implicitConversions -language:dynamics") diff --git a/compiler/test/dotty/tools/dotc/semanticdb/SemanticdbTests.scala b/compiler/test/dotty/tools/dotc/semanticdb/SemanticdbTests.scala index 3706d80fd373..5deeaed114a8 100644 --- a/compiler/test/dotty/tools/dotc/semanticdb/SemanticdbTests.scala +++ b/compiler/test/dotty/tools/dotc/semanticdb/SemanticdbTests.scala @@ -26,7 +26,7 @@ import dotty.tools.dotc.util.SourceFile SemanticdbTests().runExpectTest(updateExpectFiles = true) @Category(Array(classOf[BootstrappedOnlyTests])) -class SemanticdbTests with +class SemanticdbTests: val javaFile = FileSystems.getDefault.getPathMatcher("glob:**.java") val scalaFile = FileSystems.getDefault.getPathMatcher("glob:**.scala") val expectFile = FileSystems.getDefault.getPathMatcher("glob:**.expect.scala") @@ -124,7 +124,7 @@ class SemanticdbTests with end SemanticdbTests -object SemanticdbTests with +object SemanticdbTests: /** Prettyprint a text document with symbol occurrences next to each resolved identifier. * * Useful for testing purposes to ensure that SymbolOccurrence values make sense and are correct. diff --git a/compiler/test/dotty/tools/dotc/util/StackTraceTest.scala b/compiler/test/dotty/tools/dotc/util/StackTraceTest.scala index ee55d1b26dea..ef5f1b813030 100644 --- a/compiler/test/dotty/tools/dotc/util/StackTraceTest.scala +++ b/compiler/test/dotty/tools/dotc/util/StackTraceTest.scala @@ -7,7 +7,7 @@ import scala.util.chaining.given import org.junit.Assert.{assertEquals, assertTrue} import org.junit.Test -class StackTraceTest with +class StackTraceTest: val CausedBy = "Caused by: " val Suppressed = "Suppressed: " diff --git a/compiler/test/dotty/tools/scripting/ScriptingTests.scala b/compiler/test/dotty/tools/scripting/ScriptingTests.scala index 62de7a84c12b..547f525e98e4 100644 --- a/compiler/test/dotty/tools/scripting/ScriptingTests.scala +++ b/compiler/test/dotty/tools/scripting/ScriptingTests.scala @@ -10,7 +10,7 @@ import vulpix.TestConfiguration /** Runs all tests contained in `compiler/test-resources/repl/` */ -class ScriptingTests with +class ScriptingTests: extension (str: String) def dropExtension = str.reverse.dropWhile(_ != '.').drop(1).reverse diff --git a/docs/docs/internals/explicit-nulls.md b/docs/docs/internals/explicit-nulls.md index c884a0a05642..87348b46098d 100644 --- a/docs/docs/internals/explicit-nulls.md +++ b/docs/docs/internals/explicit-nulls.md @@ -111,7 +111,7 @@ The reason for casting to `x.type & T`, as opposed to just `T`, is that it allow support flow typing for paths of length greater than one. ```scala -abstract class Node with +abstract class Node: val x: String val next: Node | Null diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index 22db17b1e51f..508b4f3ef48f 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -3,10 +3,10 @@ layout: doc-page title: "Scala 3 Syntax Summary" --- -The following description of Scala tokens uses literal characters `‘c’` when +The following descriptions of Scala tokens uses literal characters `‘c’` when referring to the ASCII fragment `\u0000` – `\u007F`. -_Unicode escapes_ are used to represent the [Unicode character](https://www.w3.org/International/articles/definitions-characters/) with the given +_Unicode escapes_ are used to represent the Unicode character with the given hexadecimal code: ```ebnf @@ -17,7 +17,6 @@ hexDigit ::= ‘0’ | … | ‘9’ | ‘A’ | … | ‘F’ | ‘a’ | Informal descriptions are typeset as `“some comment”`. ### Lexical Syntax - The lexical syntax of Scala is given by the following grammar in EBNF form. @@ -29,9 +28,9 @@ letter ::= upper | lower “… and Unicode categories Lo, Lt, Nl” digit ::= ‘0’ | … | ‘9’ paren ::= ‘(’ | ‘)’ | ‘[’ | ‘]’ | ‘{’ | ‘}’ | ‘'(’ | ‘'[’ | ‘'{’ delim ::= ‘`’ | ‘'’ | ‘"’ | ‘.’ | ‘;’ | ‘,’ -opchar ::= “printableChar not matched by (whiteSpace | upper | - lower | letter | digit | paren | delim | opchar | - Unicode_Sm | Unicode_So)” +opchar ::= “printableChar not matched by (whiteSpace | upper | lower | + letter | digit | paren | delim | opchar | Unicode_Sm | + Unicode_So)” printableChar ::= “all characters in [\u0020, \u007F] inclusive” charEscapeSeq ::= ‘\’ (‘b’ | ‘t’ | ‘n’ | ‘f’ | ‘r’ | ‘"’ | ‘'’ | ‘\’) @@ -43,6 +42,7 @@ plainid ::= alphaid | op id ::= plainid | ‘`’ { charNoBackQuoteOrNewline | UnicodeEscape | charEscapeSeq } ‘`’ + | INT // interpolation id, only for quasi-quotes idrest ::= {letter | digit} [‘_’ op] quoteId ::= ‘'’ alphaid @@ -83,38 +83,29 @@ comment ::= ‘/*’ “any sequence of characters; nested comments ar nl ::= “new line character” semi ::= ‘;’ | nl {nl} +colonEol ::= ": at end of line that can start a template body" ``` -The lexical analyzer also inserts `indent` and `outdent` tokensthat represent regions of indented code [at certain points](../reference/other-new-features-indentation.html) - -In the context-free productions below we use the notation `<<< ts >>>` -to indicate a token sequence `ts` that is either enclosed in a pair of braces `{ ts }` or that constitutes an indented region `indent ts outdent`. - - ## Keywords ### Regular keywords ``` -abstract case catch class def do else -enum export extends false final finally for -given if implicit import lazy match new -null object override package private protected return -sealed super then throw trait true try -type val var while with yield -: = <- => <: :> # -@ =>> ?=> +abstract case catch class def do else enum +export extends false final finally for given if +implicit import lazy match new null object package +private protected override return super sealed then throw +trait true try type val var while with +yield +: = <- => <: :> # @ +=>> ?=> ``` ### Soft keywords ``` -derives end extension infix inline opaque open transparent using | * + - +derives end extension inline infix opaque open transparent using | * + - ``` - -See the [separate section on soft keywords](./soft-modifier.md) for additional -details on where a soft keyword is recognized. - ## Context-free Syntax The context-free syntax of Scala is given by the following EBNF @@ -156,9 +147,9 @@ FunArgTypes ::= InfixType | FunParamClause FunParamClause ::= ‘(’ TypedFunParam {‘,’ TypedFunParam } ‘)’ TypedFunParam ::= id ‘:’ Type -MatchType ::= InfixType `match` <<< TypeCaseClauses >>> +MatchType ::= InfixType `match` ‘{’ TypeCaseClauses ‘}’ InfixType ::= RefinedType {id [nl] RefinedType} InfixOp(t1, op, t2) -RefinedType ::= WithType {[nl | ‘with’] Refinement} RefinedTypeTree(t, ds) +RefinedType ::= WithType {[nl] Refinement} RefinedTypeTree(t, ds) WithType ::= AnnotType {‘with’ AnnotType} (deprecated) AnnotType ::= SimpleType {Annotation} Annotated(t, annot) @@ -182,7 +173,7 @@ FunArgType ::= Type ParamType ::= [‘=>’] ParamValueType ParamValueType ::= Type [‘*’] PostfixOp(t, "*") TypeArgs ::= ‘[’ Types ‘]’ ts -Refinement ::= <<< [RefineDcl] {semi [RefineDcl]} >>> ds +Refinement ::= ‘{’ [RefineDcl] {semi [RefineDcl]} ‘}’ ds TypeBounds ::= [‘>:’ Type] [‘<:’ Type] TypeBoundsTree(lo, hi) TypeParamBounds ::= TypeBounds {‘:’ Type} ContextBounds(typeBounds, tps) Types ::= Type {‘,’ Type} @@ -218,7 +209,7 @@ PostfixExpr ::= InfixExpr [id] InfixExpr ::= PrefixExpr | InfixExpr id [nl] InfixExpr InfixOp(expr, op, expr) | InfixExpr MatchClause -MatchClause ::= ‘match’ <<< CaseClauses >>> Match(expr, cases) +MatchClause ::= ‘match’ ‘{’ CaseClauses ‘}’ Match(expr, cases) PrefixExpr ::= [‘-’ | ‘+’ | ‘~’ | ‘!’] SimpleExpr PrefixOp(expr, op) SimpleExpr ::= SimpleRef | Literal @@ -227,8 +218,9 @@ SimpleExpr ::= SimpleRef | ‘$’ ‘{’ Block ‘}’ | Quoted | quoteId -- only inside splices - | ‘new’ ConstrApp {‘with’ ConstrApp} [TemplateBody] New(constr | templ) - | ‘new’ TemplateBody + | ‘new’ ConstrApp {‘with’ ConstrApp} New(constr | templ) + [[colonEol] TemplateBody + | ‘new’ [colonEol] TemplateBody | ‘(’ ExprsInParens ‘)’ Parens(exprs) | SimpleExpr ‘.’ id Select(expr, id) | SimpleExpr ‘.’ MatchClause @@ -245,7 +237,7 @@ ParArgumentExprs ::= ‘(’ [‘using’] ExprsInParens ‘)’ | ‘(’ [ExprsInParens ‘,’] PostfixExpr ‘:’ ‘_’ ‘*’ ‘)’ exprs :+ Typed(expr, Ident(wildcardStar)) ArgumentExprs ::= ParArgumentExprs | BlockExpr -BlockExpr ::= <<< (CaseClauses | Block) >>> +BlockExpr ::= ‘{’ (CaseClauses | Block) ‘}’ Block ::= {BlockStat semi} [BlockResult] Block(stats, expr?) BlockStat ::= Import | {Annotation {nl}} [‘implicit’ | ‘lazy’] Def @@ -364,6 +356,7 @@ EndMarkerTag ::= id | ‘if’ | ‘while’ | ‘for’ | ‘match’ | RefineDcl ::= ‘val’ ValDcl | ‘def’ DefDcl | ‘type’ {nl} TypeDcl + | INT Dcl ::= RefineDcl | ‘var’ VarDcl ValDcl ::= ids ‘:’ Type PatDef(_, ids, tpe, EmptyTree) @@ -379,7 +372,7 @@ Def ::= ‘val’ PatDef | ‘type’ {nl} TypeDcl | TmplDef PatDef ::= ids [‘:’ Type] ‘=’ Expr - | Pattern2 [‘:’ Type] ‘=’ Expr PatDef(_, pats, tpe?, expr) + | Pattern2 [‘:’ Type] ‘=’ Expr PatDef(_, pats, tpe?, expr) VarDef ::= PatDef | ids ‘:’ Type ‘=’ ‘_’ DefDef ::= DefSig [‘:’ Type] ‘=’ Expr DefDef(_, name, tparams, vparamss, tpe, expr) @@ -393,24 +386,23 @@ ClassDef ::= id ClassConstr [Template] ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsParamClauses with DefDef(_, , Nil, vparamss, EmptyTree, EmptyTree) as first stat ConstrMods ::= {Annotation} [AccessModifier] ObjectDef ::= id [Template] ModuleDef(mods, name, template) // no constructor -EnumDef ::= id ClassConstr InheritClauses EnumBody -GivenDef ::= [GivenSig] (AnnotType [‘=’ Expr] | ConstrApps TemplateBody) +EnumDef ::= id ClassConstr InheritClauses [colonEol] EnumBody +GivenDef ::= [GivenSig] (AnnotType [‘=’ Expr] | StructuralInstance) GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘:’ -- one of `id`, `DefParamClause`, `UsingParamClause` must be present +StructuralInstance ::= ConstrApp {‘with’ ConstrApp} ‘with’ TemplateBody Extension ::= ‘extension’ [DefTypeParamClause] ‘(’ DefParam ‘)’ {UsingParamClause}] ExtMethods -ExtMethods ::= ExtMethod | [nl] <<< ExtMethod {semi ExtMethod >>> +ExtMethods ::= ExtMethod | [nl] ‘{’ ExtMethod {semi ExtMethod ‘}’ ExtMethod ::= {Annotation [nl]} {Modifier} ‘def’ DefDef -Template ::= InheritClauses [TemplateBody] Template(constr, parents, self, stats) +Template ::= InheritClauses [colonEol] [TemplateBody] Template(constr, parents, self, stats) InheritClauses ::= [‘extends’ ConstrApps] [‘derives’ QualId {‘,’ QualId}] ConstrApps ::= ConstrApp ({‘,’ ConstrApp} | {‘with’ ConstrApp}) ConstrApp ::= SimpleType1 {Annotation} {ParArgumentExprs} Apply(tp, args) ConstrExpr ::= SelfInvocation - | <<< SelfInvocation {semi BlockStat} >>> + | ‘{’ SelfInvocation {semi BlockStat} ‘}’ SelfInvocation ::= ‘this’ ArgumentExprs {ArgumentExprs} -TemplateBody ::= [nl | ‘with’] <<< [SelfType] TemplateStats >>> - | ‘with’ SelfType indent TemplateStats outdent -TemplateStats ::= TemplateStat {semi TemplateStat} +TemplateBody ::= [nl] ‘{’ [SelfType] TemplateStat {semi TemplateStat} ‘}’ TemplateStat ::= Import | Export | {Annotation [nl]} {Modifier} Def @@ -422,14 +414,12 @@ TemplateStat ::= Import SelfType ::= id [‘:’ InfixType] ‘=>’ ValDef(_, name, tpt, _) | ‘this’ ‘:’ InfixType ‘=>’ -EnumBody ::= [nl | ‘with’] <<< [SelfType] EnumStats >>> - | ‘with’ [SelfType] indent EnumStats outdent -EnumStats ::= EnumStat {semi EnumStat} +EnumBody ::= [nl] ‘{’ [SelfType] EnumStat {semi EnumStat} ‘}’ EnumStat ::= TemplateStat | {Annotation [nl]} {Modifier} EnumCase EnumCase ::= ‘case’ (id ClassConstr [‘extends’ ConstrApps]] | ids) -TopStats ::= TopStat {semi TopStat} +TopStatSeq ::= TopStat {semi TopStat} TopStat ::= Import | Export | {Annotation [nl]} {Modifier} Def @@ -438,8 +428,8 @@ TopStat ::= Import | PackageObject | EndMarker | -Packaging ::= ‘package’ QualId [nl| ‘with’] <<< TopStats >>> Package(qid, stats) +Packaging ::= ‘package’ QualId [nl | colonEol] ‘{’ TopStatSeq ‘}’ Package(qid, stats) PackageObject ::= ‘package’ ‘object’ ObjectDef object with package in mods. -CompilationUnit ::= {‘package’ QualId semi} TopStats Package(qid, stats) +CompilationUnit ::= {‘package’ QualId semi} TopStatSeq Package(qid, stats) ``` diff --git a/docs/docs/reference/changed-features/compiler-plugins.md b/docs/docs/reference/changed-features/compiler-plugins.md index 7009659e0f1a..19f39ea759c4 100644 --- a/docs/docs/reference/changed-features/compiler-plugins.md +++ b/docs/docs/reference/changed-features/compiler-plugins.md @@ -62,14 +62,14 @@ import dotty.tools.dotc.core.Symbols._ import dotty.tools.dotc.plugins.{PluginPhase, StandardPlugin} import dotty.tools.dotc.transform.{Pickler, Staging} -class DivideZero extends StandardPlugin with +class DivideZero extends StandardPlugin: val name: String = "divideZero" override val description: String = "divide zero check" def init(options: List[String]): List[PluginPhase] = (new DivideZeroPhase) :: Nil -class DivideZeroPhase extends PluginPhase with +class DivideZeroPhase extends PluginPhase: import tpd._ val phaseName = "divideZero" @@ -108,7 +108,7 @@ import dotty.tools.dotc.core.Contexts.Context import dotty.tools.dotc.core.Phases.Phase import dotty.tools.dotc.plugins.ResearchPlugin -class DummyResearchPlugin extends ResearchPlugin with +class DummyResearchPlugin extends ResearchPlugin: val name: String = "dummy" override val description: String = "dummy research plugin" diff --git a/docs/docs/reference/changed-features/implicit-conversions-spec.md b/docs/docs/reference/changed-features/implicit-conversions-spec.md index 127bad7ef2cc..33557ecef72c 100644 --- a/docs/docs/reference/changed-features/implicit-conversions-spec.md +++ b/docs/docs/reference/changed-features/implicit-conversions-spec.md @@ -16,7 +16,7 @@ The standard library defines an abstract class `Conversion`: ```scala package scala @java.lang.FunctionalInterface -abstract class Conversion[-T, +U] extends Function1[T, U] with +abstract class Conversion[-T, +U] extends Function1[T, U]: def apply(x: T): U ``` diff --git a/docs/docs/reference/changed-features/implicit-resolution.md b/docs/docs/reference/changed-features/implicit-resolution.md index 49a2eec3c6ff..ed212bb44085 100644 --- a/docs/docs/reference/changed-features/implicit-resolution.md +++ b/docs/docs/reference/changed-features/implicit-resolution.md @@ -44,7 +44,7 @@ no longer applies. given a: A = A() - object o with + object o: given b: B = B() type C ``` diff --git a/docs/docs/reference/changed-features/main-functions.md b/docs/docs/reference/changed-features/main-functions.md index 29aac8f5f522..b6897762797b 100644 --- a/docs/docs/reference/changed-features/main-functions.md +++ b/docs/docs/reference/changed-features/main-functions.md @@ -61,7 +61,7 @@ The Scala compiler generates a program from a `@main` method `f` as follows: For instance, the `happyBirthDay` method above would generate additional code equivalent to the following class: ```scala -final class happyBirthday with +final class happyBirthday: import scala.util.{CommandLineParser => CLP} def main(args: Array[String]): Unit = try diff --git a/docs/docs/reference/changed-features/numeric-literals.md b/docs/docs/reference/changed-features/numeric-literals.md index ac39e4a060c5..3ac84541592f 100644 --- a/docs/docs/reference/changed-features/numeric-literals.md +++ b/docs/docs/reference/changed-features/numeric-literals.md @@ -86,7 +86,7 @@ whole numbers with a given radix, for numbers with a decimal point, and for numbers that can have both a decimal point and an exponent: ```scala -object FromDigits with +object FromDigits: /** A subclass of `FromDigits` that also allows to convert whole * number literals with a radix other than 10 @@ -130,7 +130,7 @@ class MalformedNumber(msg: String = "malformed number literal") extends FromDigi As a fully worked out example, here is an implementation of a new numeric class, `BigFloat`, that accepts numeric literals. `BigFloat` is defined in terms of a `BigInt` mantissa and an `Int` exponent: ```scala -case class BigFloat(mantissa: BigInt, exponent: Int) with +case class BigFloat(mantissa: BigInt, exponent: Int): override def toString = s"${mantissa}e${exponent}" ``` @@ -145,7 +145,7 @@ The companion object of `BigFloat` defines an `apply` constructor method to cons from a `digits` string. Here is a possible implementation: ```scala -object BigFloat with +object BigFloat: import scala.util.FromDigits def apply(digits: String): BigFloat = @@ -203,10 +203,10 @@ into a macro, i.e. make it an inline method with a splice as right-hand side. To do this, replace the `FromDigits` instance in the `BigFloat` object by the following two definitions: ```scala -object BigFloat with +object BigFloat: ... - class FromDigits extends FromDigits.Floating[BigFloat] with + class FromDigits extends FromDigits.Floating[BigFloat]: def fromDigits(digits: String) = apply(digits) given FromDigits with diff --git a/docs/docs/reference/changed-features/pattern-matching.md b/docs/docs/reference/changed-features/pattern-matching.md index 96e23336c71d..b61ce8fa886e 100644 --- a/docs/docs/reference/changed-features/pattern-matching.md +++ b/docs/docs/reference/changed-features/pattern-matching.md @@ -100,7 +100,7 @@ For example: ```scala -object Even with +object Even: def unapply(s: String): Boolean = s.size % 2 == 0 "even" match @@ -121,7 +121,7 @@ For example: ```scala -class FirstChars(s: String) extends Product with +class FirstChars(s: String) extends Product: def _1 = s.charAt(0) def _2 = s.charAt(1) @@ -130,7 +130,7 @@ class FirstChars(s: String) extends Product with def productArity: Int = ??? def productElement(n: Int): Any = ??? -object FirstChars with +object FirstChars: def unapply(s: String): FirstChars = new FirstChars(s) "Hi!" match @@ -147,11 +147,11 @@ object FirstChars with ```scala -class Nat(val x: Int) with +class Nat(val x: Int): def get: Int = x def isEmpty = x < 0 -object Nat with +object Nat: def unapply(x: Int): Nat = new Nat(x) 5 match @@ -167,7 +167,7 @@ object Nat with - Pattern-matching on exactly `N` patterns with types `P1, P2, ..., PN` ```Scala -object ProdEmpty with +object ProdEmpty: def _1: Int = ??? def _2: String = ??? def isEmpty = true @@ -199,7 +199,7 @@ type X = { ```scala -object CharList with +object CharList: def unapplySeq(s: String): Option[Seq[Char]] = Some(s.toList) "example" match @@ -221,7 +221,7 @@ object CharList with ```Scala class Foo(val name: String, val children: Int *) -object Foo with +object Foo: def unapplySeq(f: Foo): Option[(String, Seq[Int])] = Some((f.name, f.children)) diff --git a/docs/docs/reference/changed-features/structural-types.md b/docs/docs/reference/changed-features/structural-types.md index 5f2d49b455bb..9a056fb2beee 100644 --- a/docs/docs/reference/changed-features/structural-types.md +++ b/docs/docs/reference/changed-features/structural-types.md @@ -34,13 +34,13 @@ configure how fields and methods should be resolved. Here's an example of a structural type `Person`: ```scala - class Record(elems: (String, Any)*) extends Selectable with + class Record(elems: (String, Any)*) extends Selectable: private val fields = elems.toMap def selectDynamic(name: String): Any = fields(name) type Person = Record { val name: String; val age: Int } ``` - + The type `Person` adds a _refinement_ to its parent type `Record` that defines the two fields `name` and `age`. We say the refinement is _structural_ since `name` and `age` are not defined in the parent type. But they exist nevertheless as members of class `Person`. For instance, the following program would print "Emma is 42 years old.": @@ -82,10 +82,10 @@ Structural types can also be accessed using [Java reflection](https://www.oracle ```scala type Closeable = { def close(): Unit } - class FileInputStream with + class FileInputStream: def close(): Unit - class Channel with + class Channel: def close(): Unit ``` @@ -152,7 +152,7 @@ defines the necessary `selectDynamic` member. `Vehicle` could also extend some other subclass of `scala.Selectable` that implements `selectDynamic` and `applyDynamic` differently. But if it does not extend a `Selectable` at all, the code would no longer typecheck: ```scala -trait Vehicle with +trait Vehicle: val wheels: Int val i3 = new Vehicle: // i3: Vehicle diff --git a/docs/docs/reference/contextual/context-functions.md b/docs/docs/reference/contextual/context-functions.md index 56cfbf30fcc0..46b7ffa539ae 100644 --- a/docs/docs/reference/contextual/context-functions.md +++ b/docs/docs/reference/contextual/context-functions.md @@ -67,12 +67,12 @@ the aim is to construct tables like this: The idea is to define classes for `Table` and `Row` that allow the addition of elements via `add`: ```scala - class Table with + class Table: val rows = new ArrayBuffer[Row] def add(r: Row): Unit = rows += r override def toString = rows.mkString("Table(", ", ", ")") - class Row with + class Row: val cells = new ArrayBuffer[Cell] def add(c: Cell): Unit = cells += c override def toString = cells.mkString("Row(", ", ", ")") @@ -116,7 +116,7 @@ With that setup, the table construction code above compiles and expands to: As a larger example, here is a way to define constructs for checking arbitrary postconditions using an extension method `ensuring` so that the checked result can be referred to simply by `result`. The example combines opaque type aliases, context function types, and extension methods to provide a zero-overhead abstraction. ```scala -object PostConditions with +object PostConditions: opaque type WrappedResult[T] = T def result[T](using r: WrappedResult[T]): T = r diff --git a/docs/docs/reference/contextual/conversions.md b/docs/docs/reference/contextual/conversions.md index 26476e1fc3c3..5dae928c9620 100644 --- a/docs/docs/reference/contextual/conversions.md +++ b/docs/docs/reference/contextual/conversions.md @@ -6,7 +6,7 @@ title: "Implicit Conversions" Implicit conversions are defined by given instances of the `scala.Conversion` class. This class is defined in package `scala` as follows: ```scala -abstract class Conversion[-T, +U] extends (T => U) with +abstract class Conversion[-T, +U] extends (T => U): def apply (x: T): U ``` For example, here is an implicit conversion from `String` to `Token`: @@ -43,15 +43,15 @@ conversion from `Int` to `java.lang.Integer` can be defined as follows: 2. The "magnet" pattern is sometimes used to express many variants of a method. Instead of defining overloaded versions of the method, one can also let the method take one or more arguments of specially defined "magnet" types, into which various argument types can be converted. Example: ```scala - object Completions with + object Completions: // The argument "magnet" type - enum CompletionArg with + enum CompletionArg: case Error(s: String) case Response(f: Future[HttpResponse]) case Status(code: Future[StatusCode]) - object CompletionArg with + object CompletionArg: // conversions defining the possible arguments to pass to `complete` // these always come with CompletionArg diff --git a/docs/docs/reference/contextual/derivation-macro.md b/docs/docs/reference/contextual/derivation-macro.md index 44ab32612f32..012da07abfee 100644 --- a/docs/docs/reference/contextual/derivation-macro.md +++ b/docs/docs/reference/contextual/derivation-macro.md @@ -142,7 +142,7 @@ import scala.quoted._ trait Eq[T]: def eqv(x: T, y: T): Boolean -object Eq with +object Eq: given Eq[String] with def eqv(x: String, y: String) = x == y @@ -195,7 +195,7 @@ object Eq with end derived end Eq -object Macro3 with +object Macro3: extension [T](inline x: T) inline def === (inline y: T)(using eq: Eq[T]): Boolean = eq.eqv(x, y) diff --git a/docs/docs/reference/contextual/derivation.md b/docs/docs/reference/contextual/derivation.md index bd6e29c07dc6..c2fbb9ecda63 100644 --- a/docs/docs/reference/contextual/derivation.md +++ b/docs/docs/reference/contextual/derivation.md @@ -40,7 +40,7 @@ They also provide minimal term level infrastructure to allow higher level librar derivation support. ```scala -sealed trait Mirror with +sealed trait Mirror: /** the type being mirrored */ type MirroredType @@ -57,7 +57,7 @@ sealed trait Mirror with /** The names of the elements of the type */ type MirroredElemLabels <: Tuple -object Mirror with +object Mirror: /** The Mirror for a product type */ trait Product extends Mirror: @@ -242,7 +242,7 @@ inline def summonAll[T <: Tuple]: List[Eq[_]] = trait Eq[T]: def eqv(x: T, y: T): Boolean -object Eq with +object Eq: given Eq[Int] with def eqv(x: Int, y: Int) = x == y diff --git a/docs/docs/reference/contextual/extension-methods.md b/docs/docs/reference/contextual/extension-methods.md index 647fd95afc1e..a89658d14608 100644 --- a/docs/docs/reference/contextual/extension-methods.md +++ b/docs/docs/reference/contextual/extension-methods.md @@ -174,7 +174,7 @@ There are four possible ways for an extension method to be applicable: Here is an example for the first rule: ```scala -trait IntOps with +trait IntOps: extension (i: Int) def isZero: Boolean = i == 0 extension (i: Int) def safeMod(x: Int): Option[Int] = @@ -182,13 +182,13 @@ trait IntOps with if x.isZero then None else Some(i % x) -object IntOpsEx extends IntOps with +object IntOpsEx extends IntOps: extension (i: Int) def safeDiv(x: Int): Option[Int] = // extension method brought into scope via inheritance from IntOps if x.isZero then None else Some(i / x) -trait SafeDiv with +trait SafeDiv: import IntOpsEx._ // brings safeDiv and safeMod into scope extension (i: Int) def divide(d: Int): Option[(Int, Int)] = @@ -209,9 +209,9 @@ given ops1: IntOps with {} // brings safeMod into scope By the third and fourth rule, an extension method is available if it is in the implicit scope of the receiver type or in a given instance in that scope. Example: ```scala -class List[T] with +class List[T]: ... -object List with +object List: ... extension [T](xs: List[List[T]]) def flatten: List[T] = xs.foldLeft(Nil: List[T])(_ ++ _) diff --git a/docs/docs/reference/contextual/given-imports.md b/docs/docs/reference/contextual/given-imports.md index c3c342b571bf..a6d813d06ee6 100644 --- a/docs/docs/reference/contextual/given-imports.md +++ b/docs/docs/reference/contextual/given-imports.md @@ -6,12 +6,12 @@ title: "Importing Givens" A special form of import wildcard selector is used to import given instances. Example: ```scala -object A with +object A: class TC given tc: TC = ??? def f(using TC) = ??? -object B with +object B: import A._ import A.given ... @@ -22,7 +22,7 @@ of `A` _except_ the given instance `tc`. Conversely, the second import `import A The two import clauses can also be merged into one: ```scala -object B with +object B: import A.{given, _} ... ``` @@ -58,7 +58,7 @@ Importing all given instances of a parameterized type is expressed by wildcard a For instance, assuming the object ```scala -object Instances with +object Instances: given intOrd: Ordering[Int] = ... given listOrd[T: Ordering]: Ordering[List[T]] = ... given ec: ExecutionContext = ... diff --git a/docs/docs/reference/contextual/givens.md b/docs/docs/reference/contextual/givens.md index 2f3b8c61121e..b289b6cf9bca 100644 --- a/docs/docs/reference/contextual/givens.md +++ b/docs/docs/reference/contextual/givens.md @@ -7,7 +7,7 @@ Given instances (or, simply, "givens") define "canonical" values of certain type that serve for synthesizing arguments to [context parameters](./using-clauses.md). Example: ```scala -trait Ord[T] with +trait Ord[T]: def compare(x: T, y: T): Int extension (x: T) def < (y: T) = compare(x, y) < 0 extension (x: T) def > (y: T) = compare(x, y) > 0 @@ -130,7 +130,7 @@ import scala.util.NotGiven trait Tagged[A] case class Foo[A](value: Boolean) -object Foo with +object Foo: given fooTagged[A](using Tagged[A]): Foo[A] = Foo(true) given fooNotTagged[A](using NotGiven[Tagged[A]]): Foo[A] = Foo(false) @@ -153,10 +153,11 @@ Here is the syntax for given instances: ``` TmplDef ::= ... | ‘given’ GivenDef -GivenDef ::= [GivenSig] ConstrApps TemplateBody +GivenDef ::= [GivenSig] StructuralInstance | [GivenSig] AnnotType ‘=’ Expr | [GivenSig] AnnotType GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘:’ +StructuralInstance ::= ConstrApp {‘with’ ConstrApp} ‘with’ TemplateBody ``` A given instance starts with the reserved word `given` and an optional _signature_. The signature diff --git a/docs/docs/reference/contextual/multiversal-equality.md b/docs/docs/reference/contextual/multiversal-equality.md index 8df384b28de8..35a232903576 100644 --- a/docs/docs/reference/contextual/multiversal-equality.md +++ b/docs/docs/reference/contextual/multiversal-equality.md @@ -54,7 +54,7 @@ import annotation.implicitNotFound @implicitNotFound("Values of types ${L} and ${R} cannot be compared with == or !=") sealed trait CanEqual[-L, -R] -object CanEqual with +object CanEqual: object derived extends CanEqual[Any, Any] ``` @@ -172,7 +172,7 @@ we are dealing with a refinement of pre-existing, universal equality. It is best Say you want to come up with a safe version of the `contains` method on `List[T]`. The original definition of `contains` in the standard library was: ```scala -class List[+T] with +class List[+T]: ... def contains(x: Any): Boolean ``` diff --git a/docs/docs/reference/contextual/type-classes.md b/docs/docs/reference/contextual/type-classes.md index 742e4022481a..5911eff48eed 100644 --- a/docs/docs/reference/contextual/type-classes.md +++ b/docs/docs/reference/contextual/type-classes.md @@ -16,10 +16,10 @@ Here are some examples of common type classes: Here's the `Monoid` type class definition: ```scala -trait SemiGroup[T] with +trait SemiGroup[T]: extension (x: T) def combine (y: T): T -trait Monoid[T] extends SemiGroup[T] with +trait Monoid[T] extends SemiGroup[T]: def unit: T ``` @@ -49,7 +49,7 @@ def combineAll[T: Monoid](xs: List[T]): T = To get rid of the `summon[...]` we can define a `Monoid` object as follows: ```scala -object Monoid with +object Monoid: def apply[T](using m: Monoid[T]) = m ``` @@ -68,7 +68,7 @@ Therefore we write it `F[_]`, hinting that the type `F` takes another type as ar The definition of a generic `Functor` would thus be written as: ```scala -trait Functor[F[_]] with +trait Functor[F[_]]: def map[A, B](x: F[A], f: A => B): F[B] ``` @@ -100,7 +100,7 @@ That's a first step, but in practice we probably would like the `map` function t As in the previous example of Monoids, [`extension` methods](extension-methods.md) help achieving that. Let's re-define the `Functor` type class with extension methods. ```scala -trait Functor[F[_]] with +trait Functor[F[_]]: extension [A](x: F[A]) def map[B](f: A => B): F[B] ``` @@ -138,7 +138,7 @@ That's where `Monad` comes in. A `Monad` for type `F[_]` is a `Functor[F]` with Here is the translation of this definition in Scala 3: ```scala -trait Monad[F[_]] extends Functor[F] with +trait Monad[F[_]] extends Functor[F]: /** The unit value for a monad */ def pure[A](x: A): F[A] diff --git a/docs/docs/reference/dropped-features/auto-apply.md b/docs/docs/reference/dropped-features/auto-apply.md index 78d699e81596..9ff9aa648502 100644 --- a/docs/docs/reference/dropped-features/auto-apply.md +++ b/docs/docs/reference/dropped-features/auto-apply.md @@ -73,10 +73,10 @@ by a nullary method or _vice versa_. Instead, both methods must agree exactly in their parameter lists. ```scala -class A with +class A: def next(): Int -class B extends A with +class B extends A: def next: Int // overriding error: incompatible type ``` diff --git a/docs/docs/reference/dropped-features/delayed-init.md b/docs/docs/reference/dropped-features/delayed-init.md index f1bab9687e10..ca640185252d 100644 --- a/docs/docs/reference/dropped-features/delayed-init.md +++ b/docs/docs/reference/dropped-features/delayed-init.md @@ -20,7 +20,7 @@ for benchmarking! Also, if you want to access the command line arguments, you need to use an explicit `main` method for that. ```scala -object Hello with +object Hello: def main(args: Array[String]) = println(s"Hello, ${args(0)}") ``` diff --git a/docs/docs/reference/enums/adts.md b/docs/docs/reference/enums/adts.md index 463378d2391d..6bfb188b349d 100644 --- a/docs/docs/reference/enums/adts.md +++ b/docs/docs/reference/enums/adts.md @@ -8,7 +8,7 @@ types (ADTs) and their generalized version (GADTs). Here is an example how an `Option` type can be represented as an ADT: ```scala -enum Option[+T] with +enum Option[+T]: case Some(x: T) case None ``` @@ -23,7 +23,7 @@ The `extends` clauses that were omitted in the example above can also be given explicitly: ```scala -enum Option[+T] with +enum Option[+T]: case Some(x: T) extends Option[T] case None extends Option[Nothing] ``` @@ -59,7 +59,7 @@ As all other enums, ADTs can define methods. For instance, here is `Option` agai `isDefined` method and an `Option(...)` constructor in its companion object. ```scala -enum Option[+T] with +enum Option[+T]: case Some(x: T) case None @@ -67,7 +67,7 @@ enum Option[+T] with case None => false case some => true -object Option with +object Option: def apply[T >: Null](x: T): Option[T] = if x == null then None else Some(x) diff --git a/docs/docs/reference/enums/enums.md b/docs/docs/reference/enums/enums.md index 877aac6d3a66..219a831a445e 100644 --- a/docs/docs/reference/enums/enums.md +++ b/docs/docs/reference/enums/enums.md @@ -6,7 +6,7 @@ title: "Enumerations" An enumeration is used to define a type consisting of a set of named values. ```scala -enum Color with +enum Color: case Red, Green, Blue ``` @@ -79,7 +79,7 @@ end Planet It is also possible to define an explicit companion object for an enum: ```scala -object Planet with +object Planet: def main(args: Array[String]) = val earthWeight = args(0).toDouble val mass = earthWeight / Earth.surfaceGravity @@ -153,7 +153,7 @@ For a more in-depth example of using Scala 3 enums from Java, see [this test](ht ### Implementation Enums are represented as `sealed` classes that extend the `scala.reflect.Enum` trait. -This trait defines a single public method, `ordinal` with +This trait defines a single public method, `ordinal`: ```scala package scala.reflect diff --git a/docs/docs/reference/metaprogramming/erased-terms.md b/docs/docs/reference/metaprogramming/erased-terms.md index bd5e861408c7..dde296ebff83 100644 --- a/docs/docs/reference/metaprogramming/erased-terms.md +++ b/docs/docs/reference/metaprogramming/erased-terms.md @@ -20,10 +20,10 @@ final class Off extends State @implicitNotFound("State must be Off") class IsOff[S <: State] -object IsOff with +object IsOff: given isOff: IsOff[Off] = new IsOff[Off] -class Machine[S <: State] with +class Machine[S <: State]: def turnedOn(using IsOff[S]): Machine[On] = new Machine[On] val m = new Machine[Off] @@ -118,24 +118,24 @@ final class Off extends State @implicitNotFound("State must be Off") class IsOff[S <: State] -object IsOff with +object IsOff: // will not be called at runtime for turnedOn, the // compiler will only require that this evidence exists given IsOff[Off] = new IsOff[Off] @implicitNotFound("State must be On") class IsOn[S <: State] -object IsOn with +object IsOn: // will not exist at runtime, the compiler will only // require that this evidence exists at compile time erased given IsOn[On] = new IsOn[On] -class Machine[S <: State] private () with +class Machine[S <: State] private (): // ev will disappear from both functions def turnedOn(using erased ev: IsOff[S]): Machine[On] = new Machine[On] def turnedOff(using erased ev: IsOn[S]): Machine[Off] = new Machine[Off] -object Machine with +object Machine: def newMachine(): Machine[Off] = new Machine[Off] @main def test = @@ -163,7 +163,7 @@ sealed trait State final class On extends State final class Off extends State -class Machine[S <: State] with +class Machine[S <: State]: transparent inline def turnOn(): Machine[On] = inline erasedValue[S] match case _: Off => new Machine[On] @@ -174,7 +174,7 @@ class Machine[S <: State] with case _: On => new Machine[Off] case _: Off => error("Turning off an already turned off machine") -object Machine with +object Machine: def newMachine(): Machine[Off] = println("newMachine") new Machine[Off] diff --git a/docs/docs/reference/metaprogramming/inline.md b/docs/docs/reference/metaprogramming/inline.md index 6484cf2cac83..ba18f55d76d8 100644 --- a/docs/docs/reference/metaprogramming/inline.md +++ b/docs/docs/reference/metaprogramming/inline.md @@ -9,10 +9,10 @@ title: Inline definition will be inlined at the point of use. Example: ```scala -object Config with +object Config: inline val logging = false -object Logger with +object Logger: private var indent = 0 @@ -143,11 +143,11 @@ Inline methods can override other non-inline methods. The rules are as follows: 1. If an inline method `f` implements or overrides another, non-inline method, the inline method can also be invoked at runtime. For instance, consider the scenario: ```scala - abstract class A with + abstract class A: def f: Int def g: Int = f - class B extends A with + class B extends A: inline def f = 22 override inline def g = f + 11 @@ -168,7 +168,7 @@ Inline methods can override other non-inline methods. The rules are as follows: 3. Inline methods can also be abstract. An abstract inline method can be implemented only by other inline methods. It cannot be invoked directly: ```scala - abstract class A with + abstract class A: inline def f: Int object B extends A: @@ -235,7 +235,7 @@ inline val four: 4 = 4 It is also possible to have inline vals of types that do not have a syntax, such as `Short(4)`. ```scala -trait InlineConstants with +trait InlineConstants: inline val myShort: Short object Constants extends InlineConstants: @@ -250,7 +250,7 @@ specialized to a more precise type upon expansion. Example: ```scala class A -class B extends A with +class B extends A: def m = true transparent inline def choose(b: Boolean): A = @@ -535,7 +535,7 @@ not. We can create a set of implicit definitions like this: ```scala trait SetFor[T, S <: Set[T]] -class LowPriority with +class LowPriority: implicit def hashSetFor[T]: SetFor[T, HashSet[T]] = ... object SetsFor extends LowPriority: diff --git a/docs/docs/reference/metaprogramming/macros-spec.md b/docs/docs/reference/metaprogramming/macros-spec.md index e855dd7a7746..8bdee4ba1eba 100644 --- a/docs/docs/reference/metaprogramming/macros-spec.md +++ b/docs/docs/reference/metaprogramming/macros-spec.md @@ -211,7 +211,7 @@ given AsFunction1[T, U]: Conversion[Expr[T => U], Expr[T] => Expr[U]] with ``` This assumes an extractor ```scala -object Lambda with +object Lambda: def unapply[T, U](x: Expr[T => U]): Option[Expr[T] => Expr[U]] ``` Once we allow inspection of code via extractors, it’s tempting to also diff --git a/docs/docs/reference/metaprogramming/macros.md b/docs/docs/reference/metaprogramming/macros.md index 09da411faa15..997252176fc3 100644 --- a/docs/docs/reference/metaprogramming/macros.md +++ b/docs/docs/reference/metaprogramming/macros.md @@ -168,7 +168,7 @@ In some cases we want to remove the lambda from the code, for this we provide th describing a function into a function mapping trees to trees. ```scala -object Expr with +object Expr: ... def betaReduce[...](...)(...): ... = ... ``` @@ -231,7 +231,7 @@ a compiler through staging. ```scala import scala.quoted._ -enum Exp with +enum Exp: case Num(n: Int) case Plus(e1: Exp, e2: Exp) case Var(x: String) @@ -284,7 +284,7 @@ The `Expr.apply` method is defined in package `quoted`: ```scala package quoted -object Expr with +object Expr: ... def apply[T: ToExpr](x: T)(using Quotes): Expr[T] = summon[ToExpr[T]].toExpr(x) @@ -391,7 +391,7 @@ a macro library and a quoted program. For instance, here’s the `assert` macro again together with a program that calls `assert`. ```scala -object Macros with +object Macros: inline def assert(inline expr: Boolean): Unit = ${ assertImpl('expr) } @@ -525,7 +525,7 @@ Assume we have two methods, one `map` that takes an `Expr[Array[T]]` and a function `f` and one `sum` that performs a sum by delegating to `map`. ```scala -object Macros with +object Macros: def map[T](arr: Expr[Array[T]], f: Expr[T] => Expr[Unit]) (using Type[T], Quotes): Expr[Unit] = '{ diff --git a/docs/docs/reference/metaprogramming/tasty-inspect.md b/docs/docs/reference/metaprogramming/tasty-inspect.md index f02b7fdbdb08..3547b8939a3d 100644 --- a/docs/docs/reference/metaprogramming/tasty-inspect.md +++ b/docs/docs/reference/metaprogramming/tasty-inspect.md @@ -21,7 +21,7 @@ To inspect the trees of a TASTy file a consumer can be defined in the following import scala.quoted._ import scala.tasty.inspector._ -class MyInspector extends TastyInspector with +class MyInspector extends TastyInspector: protected def processCompilationUnit(using Quotes)(tree: quotes.reflect.Tree): Unit = import quotes.reflect._ // Do something with the tree @@ -30,7 +30,7 @@ class MyInspector extends TastyInspector with Then the consumer can be instantiated with the following code to get the tree of the `foo/Bar.tasty` file. ```scala -object Test with +object Test: def main(args: Array[String]): Unit = new MyInspector().inspectTastyFiles("foo/Bar.tasty") ``` diff --git a/docs/docs/reference/new-types/dependent-function-types-spec.md b/docs/docs/reference/new-types/dependent-function-types-spec.md index 0cf3a8c00b16..5f9bf9cf5f6a 100644 --- a/docs/docs/reference/new-types/dependent-function-types-spec.md +++ b/docs/docs/reference/new-types/dependent-function-types-spec.md @@ -75,7 +75,7 @@ In the following example the depend type `f.Eff` refers to the effect type `CanT trait Effect // Type X => Y -abstract class Fun[-X, +Y] with +abstract class Fun[-X, +Y]: type Eff <: Effect def apply(x: X): Eff ?=> Y @@ -85,11 +85,11 @@ class CanIO extends Effect given ct: CanThrow = new CanThrow given ci: CanIO = new CanIO -class I2S extends Fun[Int, String] with +class I2S extends Fun[Int, String]: type Eff = CanThrow def apply(x: Int) = x.toString -class S2I extends Fun[String, Int] with +class S2I extends Fun[String, Int]: type Eff = CanIO def apply(x: String) = x.length diff --git a/docs/docs/reference/new-types/intersection-types.md b/docs/docs/reference/new-types/intersection-types.md index 1cbb99f1e9f0..a2cfc1f380c8 100644 --- a/docs/docs/reference/new-types/intersection-types.md +++ b/docs/docs/reference/new-types/intersection-types.md @@ -10,7 +10,7 @@ Used on types, the `&` operator creates an intersection type. The type `S & T` represents values that are of the type `S` and `T` at the same time. ```scala -trait Resettable with +trait Resettable: def reset(): Unit trait Growable[T]: @@ -34,10 +34,10 @@ If a member appears in both `A` and `B`, its type in `A & B` is the intersection of its type in `A` and its type in `B`. For instance, assume the definitions: ```scala -trait A with +trait A: def children: List[A] -trait B with +trait B: def children: List[B] val x: A & B = new C @@ -59,7 +59,7 @@ So if one defines a class `C` that inherits `A` and `B`, one needs to give at that point a definition of a `children` method with the required type. ```scala -class C extends A, B with +class C extends A, B: def children: List[A & B] = ??? ``` diff --git a/docs/docs/reference/other-new-features/creator-applications.md b/docs/docs/reference/other-new-features/creator-applications.md index 6604edd8dc12..387202720f9c 100644 --- a/docs/docs/reference/other-new-features/creator-applications.md +++ b/docs/docs/reference/other-new-features/creator-applications.md @@ -9,7 +9,7 @@ function application, without needing to write `new`. Scala 3 generalizes this scheme to all concrete classes. Example: ```scala -class StringBuilder(s: String) with +class StringBuilder(s: String): def this() = this("") StringBuilder("abc") // same as new StringBuilder("abc") @@ -20,7 +20,7 @@ This works since a companion object with two `apply` methods is generated together with the class. The object looks like this: ```scala -object StringBuilder with +object StringBuilder: inline def apply(s: String): StringBuilder = new StringBuilder(s) inline def apply(): StringBuilder = new StringBuilder() ``` diff --git a/docs/docs/reference/other-new-features/explicit-nulls.md b/docs/docs/reference/other-new-features/explicit-nulls.md index 82f61eead706..b531774ac1d5 100644 --- a/docs/docs/reference/other-new-features/explicit-nulls.md +++ b/docs/docs/reference/other-new-features/explicit-nulls.md @@ -39,7 +39,7 @@ The new type system is unsound with respect to `null`. This means there are stil The unsoundness happens because uninitialized fields in a class start out as `null`: ```scala -class C with +class C: val f: String = foo(f) def foo(f2: String): String = f2 @@ -114,7 +114,7 @@ Specifically, we patch ``` ==> ```scala - class C with + class C: val s: String|UncheckedNull val x: Int ``` @@ -132,7 +132,7 @@ Specifically, we patch Notice this is rule is sometimes too conservative, as witnessed by ```scala - class InScala with + class InScala: val c: C[Bool] = ??? // C as above val b: Bool = c.foo() // no longer typechecks, since foo now returns Bool|Null ``` @@ -169,7 +169,7 @@ Specifically, we patch ``` ==> ```scala - class BoxFactory[T] with + class BoxFactory[T]: def makeBox(): Box[T | UncheckedNull] | UncheckedNull def makeCrazyBoxes(): List[Box[List[T] | UncheckedNull]] | UncheckedNull ``` @@ -195,7 +195,7 @@ Specifically, we patch ``` ==> ```scala - class Constants with + class Constants: val NAME: String("name") = "name" val AGE: Int(0) = 0 val CHAR: Char('a') = 'a' @@ -215,7 +215,7 @@ Specifically, we patch ``` ==> ```scala - class C with + class C: val name: String def getNames(prefix: String | UncheckedNull): List[String] // we still need to nullify the paramter types def getBoxedName(): Box[String | UncheckedNull] // we don't append `UncheckedNull` to the outmost level, but we still need to nullify inside diff --git a/docs/docs/reference/other-new-features/export.md b/docs/docs/reference/other-new-features/export.md index 697939f053ae..2a7aaada28ef 100644 --- a/docs/docs/reference/other-new-features/export.md +++ b/docs/docs/reference/other-new-features/export.md @@ -9,16 +9,16 @@ An export clause defines aliases for selected members of an object. Example: class BitMap class InkJet -class Printer with +class Printer: type PrinterType def print(bits: BitMap): Unit = ??? def status: List[String] = ??? -class Scanner with +class Scanner: def scan(): BitMap = ??? def status: List[String] = ??? -class Copier with +class Copier: private val printUnit = new Printer { type PrinterType = InkJet } private val scanUnit = new Scanner diff --git a/docs/docs/reference/other-new-features/indentation.md b/docs/docs/reference/other-new-features/indentation.md index cab4be5978ff..08cd79f02a71 100644 --- a/docs/docs/reference/other-new-features/indentation.md +++ b/docs/docs/reference/other-new-features/indentation.md @@ -58,12 +58,15 @@ There are two rules: An indentation region can start + - after the leading parameters of an `extension`, or + - after a `with` in a given instance, or + - after a ": at end of line" token (see below) - after one of the following tokens: + ``` - = => ?=> <- catch do else finally for if - match return then throw try with while yield + = => ?=> <- catch do else finally for + if match return then throw try while yield ``` - - after the leading parameters of an `extension`. If an `` is inserted, the indentation width of the token on the next line is pushed onto `IW`, which makes it the new current indentation width. @@ -71,7 +74,7 @@ There are two rules: 2. An `` is inserted at a line break, if - the first token on the next line has an indentation width strictly less - than the current indentation width, and + than the current indentation width, and - the last token on the previous line is not one of the following tokens which indicate that the previous statement continues: ``` @@ -88,7 +91,7 @@ There are two rules: - An `` is also inserted if the next token following a statement sequence starting with an `` closes an indentation region, i.e. is one of `then`, `else`, `do`, `catch`, `finally`, `yield`, `}`, `)`, `]` or `case`. - - An `` is finally inserted in front of a comma that follows a statement sequence starting with an `` if the indented region is itself enclosed in parentheses + An `` is finally inserted in front of a comma that follows a statement sequence starting with an `` if the indented region is itself enclosed in parentheses It is an error if the indentation width of the token following an `` does not match the indentation of some previous line in the enclosing indentation region. For instance, the following would be rejected. @@ -116,16 +119,16 @@ Analogous rules apply for enum bodies and local packages containing nested defin With these new rules, the following constructs are all valid: ```scala -trait A with +trait A: def f: Int -class C(x: Int) extends A with +class C(x: Int) extends A: def f = x -object O with +object O: def f = 3 -enum Color with +enum Color: case Red, Green, Blue new A: @@ -255,7 +258,7 @@ For instance, the following end markers are all legal: ```scala package p1.p2: - abstract class C() with + abstract class C(): def this(x: Int) = this() @@ -284,7 +287,7 @@ package p1.p2: def f: String end C - object C with + object C: given C = new C: def f = "!" @@ -326,7 +329,7 @@ TopStat ::= ... | EndMarker Here is a (somewhat meta-circular) example of code using indentation. It provides a concrete representation of indentation widths as defined above together with efficient operations for constructing and comparing indentation widths. ```scala -enum IndentWidth with +enum IndentWidth: case Run(ch: Char, n: Int) case Conc(l: IndentWidth, r: Run) @@ -355,7 +358,7 @@ enum IndentWidth with case Conc(l, r) => s"$l, $r" -object IndentWidth with +object IndentWidth: private inline val MaxCached = 40 private val spaces = IArray.tabulate(MaxCached + 1)(new Run(' ', _)) diff --git a/docs/docs/reference/other-new-features/matchable.md b/docs/docs/reference/other-new-features/matchable.md index 3513e0f20049..c4814af64f3f 100644 --- a/docs/docs/reference/other-new-features/matchable.md +++ b/docs/docs/reference/other-new-features/matchable.md @@ -75,7 +75,7 @@ extended by both `AnyVal` and `AnyRef`. Since `Matchable` is a supertype of ever Here is the hierarchy of top-level classes and traits with their defined methods: ```scala -abstract class Any with +abstract class Any: def getClass def isInstanceOf def asInstanceOf @@ -102,7 +102,7 @@ Matchable warning is turned on. The most common such method is the universal `equals` method. It will have to be written as in the following example: ```scala -class C(val x: String) with +class C(val x: String): override def equals(that: Any): Boolean = that.asInstanceOf[Matchable] match diff --git a/docs/docs/reference/other-new-features/opaques-details.md b/docs/docs/reference/other-new-features/opaques-details.md index ba7f843dcd28..ef8d6ab0492f 100644 --- a/docs/docs/reference/other-new-features/opaques-details.md +++ b/docs/docs/reference/other-new-features/opaques-details.md @@ -33,7 +33,7 @@ type T >: L <: U A special case arises if the opaque type alias is defined in an object. Example: ```scala -object o with +object o: opaque type T = R ``` @@ -44,7 +44,7 @@ that `o.this.T` equals `R`. The two equalities compose. That is, inside `o`, it also known that `o.T` is equal to `R`. This means the following code type-checks: ```scala -object o with +object o: opaque type T = Int val x: Int = id(2) def id(x: o.T): o.T = x @@ -88,7 +88,7 @@ objects and classes and in all other source files. Example: opaque type A = String val x: A = "abc" -object obj with +object obj: val y: A = "abc" // error: found: "abc", required: A // in test2.scala @@ -100,7 +100,7 @@ object test1$package: opaque type A = String val x: A = "abc" -object obj with +object obj: val y: A = "abc" // error: cannot assign "abc" to opaque type alias A ``` The opaque type alias `A` is transparent in its scope, which includes the definition of `x`, but not the definitions of `obj` and `y`. diff --git a/docs/docs/reference/other-new-features/opaques.md b/docs/docs/reference/other-new-features/opaques.md index 9a19cdeb2b35..5bed38293b21 100644 --- a/docs/docs/reference/other-new-features/opaques.md +++ b/docs/docs/reference/other-new-features/opaques.md @@ -6,11 +6,11 @@ title: "Opaque Type Aliases" Opaque types aliases provide type abstraction without any overhead. Example: ```scala -object Logarithms with +object Logarithms: opaque type Logarithm = Double - object Logarithm with + object Logarithm: // These are the two ways to lift to the Logarithm type @@ -63,7 +63,7 @@ l / l2 // error: `/` is not a member of Logarithm Opaque type aliases can also come with bounds. Example: ```scala -object Access with +object Access: opaque type Permissions = Int opaque type PermissionChoice = Int @@ -110,7 +110,7 @@ it known outside the `Access` object that `Permission` is a subtype of the other two types. Hence, the following usage scenario type-checks. ```scala -object User with +object User: import Access._ case class Item(rights: Permissions) diff --git a/docs/docs/reference/other-new-features/open-classes.md b/docs/docs/reference/other-new-features/open-classes.md index 1de2e57fc66d..c1ee2def453b 100644 --- a/docs/docs/reference/other-new-features/open-classes.md +++ b/docs/docs/reference/other-new-features/open-classes.md @@ -8,7 +8,7 @@ An `open` modifier on a class signals that the class is planned for extensions. // File Writer.scala package p -open class Writer[T] with +open class Writer[T]: /** Sends to stdout, can be overridden */ def send(x: T) = println(x) @@ -20,7 +20,7 @@ end Writer // File EncryptedWriter.scala package p -class EncryptedWriter[T: Encryptable] extends Writer[T] with +class EncryptedWriter[T: Encryptable] extends Writer[T]: override def send(x: T) = super.send(encrypt(x)) ``` An open class typically comes with some documentation that describes diff --git a/docs/docs/reference/other-new-features/safe-initialization.md b/docs/docs/reference/other-new-features/safe-initialization.md index 34ef34c6f85f..2d115745bb57 100644 --- a/docs/docs/reference/other-new-features/safe-initialization.md +++ b/docs/docs/reference/other-new-features/safe-initialization.md @@ -14,11 +14,11 @@ To get a feel of how it works, we first show several examples below. Given the following code snippet: ``` scala -abstract class AbstractFile with +abstract class AbstractFile: def name: String val extension: String = name.substring(4) -class RemoteFile(url: String) extends AbstractFile with +class RemoteFile(url: String) extends AbstractFile: val localFile: String = s"${url.##}.tmp" // error: usage of `localFile` before it's initialized def name: String = localFile ``` @@ -39,7 +39,7 @@ The checker will report: Given the code below: ``` scala -object Trees with +object Trees: class ValDef { counter += 1 } class EmptyValDef extends ValDef val theEmptyValDef = new EmptyValDef @@ -63,11 +63,11 @@ The checker will report: Given the code below: ``` scala -abstract class Parent with +abstract class Parent: val f: () => String = () => this.message def message: String -class Child extends Parent with +class Child extends Parent: val a = f() val b = "hello" // error def message: String = b @@ -122,11 +122,11 @@ following example shows: ``` scala class MyException(val b: B) extends Exception("") -class A with +class A: val b = try { new B } catch { case myEx: MyException => myEx.b } println(b.a) -class B with +class B: throw new MyException(this) val a: Int = 1 ``` @@ -141,10 +141,10 @@ field points to an initialized object may not later point to an object under initialization. As an example, the following code will be rejected: ``` scala -trait Reporter with +trait Reporter: def report(msg: String): Unit -class FileReporter(ctx: Context) extends Reporter with +class FileReporter(ctx: Context) extends Reporter: ctx.typer.reporter = this // ctx now reaches an uninitialized object val file: File = new File("report.txt") def report(msg: String) = file.write(msg) @@ -214,11 +214,11 @@ project boundaries. For example, the following code passes the check when the two classes are defined in the same project: ```Scala -class Base with +class Base: private val map: mutable.Map[Int, String] = mutable.Map.empty def enter(k: Int, v: String) = map(k) = v -class Child extends Base with +class Child extends Base: enter(1, "one") enter(2, "two") ``` diff --git a/docs/docs/reference/other-new-features/targetName.md b/docs/docs/reference/other-new-features/targetName.md index ef43e1086897..572d7a5e2146 100644 --- a/docs/docs/reference/other-new-features/targetName.md +++ b/docs/docs/reference/other-new-features/targetName.md @@ -8,7 +8,7 @@ A `@targetName` annotation on a definition defines an alternate name for the imp ```scala import scala.annotation.targetName -object VecOps with +object VecOps: extension [T](xs: Vec[T]) @targetName("append") def ++= [T] (ys: Vec[T]): Vec[T] = ... @@ -70,9 +70,9 @@ between two definitions that have otherwise the same names and types. So the fol ```scala import annotation.targetName -class A with +class A: def f(): Int = 1 -class B extends A with +class B extends A: @targetName("g") def f(): Int = 2 ``` @@ -98,9 +98,9 @@ be present in the original code. So the following example would also be in error ```scala import annotation.targetName -class A with +class A: def f(): Int = 1 -class B extends A with +class B extends A: @targetName("f") def g(): Int = 2 ``` @@ -109,7 +109,7 @@ different names. But once we switch to target names, there is a clash that is re ``` -- [E120] Naming Error: test.scala:4:6 ----------------------------------------- -4 |class B extends A with +4 |class B extends A: | ^ | Name clash between defined and inherited member: | def f(): Int in class A at line 3 and diff --git a/docs/docs/reference/other-new-features/threadUnsafe-annotation.md b/docs/docs/reference/other-new-features/threadUnsafe-annotation.md index 56ae89ea7e96..2c5a3df9c82c 100644 --- a/docs/docs/reference/other-new-features/threadUnsafe-annotation.md +++ b/docs/docs/reference/other-new-features/threadUnsafe-annotation.md @@ -12,6 +12,6 @@ a `lazy val`. When this annotation is used, the initialization of the ```scala import scala.annotation.threadUnsafe -class Hello with +class Hello: @threadUnsafe lazy val x: Int = 1 ``` diff --git a/docs/docs/reference/other-new-features/trait-parameters.md b/docs/docs/reference/other-new-features/trait-parameters.md index fd200c92bf53..1655e338b32c 100644 --- a/docs/docs/reference/other-new-features/trait-parameters.md +++ b/docs/docs/reference/other-new-features/trait-parameters.md @@ -9,7 +9,7 @@ Scala 3 allows traits to have parameters, just like classes have parameters. trait Greeting(val name: String): def msg = s"How are you, $name" -class C extends Greeting("Bob") with +class C extends Greeting("Bob"): println(msg) ``` diff --git a/docs/docs/reference/other-new-features/type-test.md b/docs/docs/reference/other-new-features/type-test.md index 52a10713db49..72323c4a0bc4 100644 --- a/docs/docs/reference/other-new-features/type-test.md +++ b/docs/docs/reference/other-new-features/type-test.md @@ -19,7 +19,7 @@ The second case is when an extractor takes an argument that is not a subtype of (x: X) match case y @ Y(n) => -object Y with +object Y: def unapply(x: Y): Some[Int] = ... ``` @@ -115,7 +115,7 @@ Given the following abstract definition of Peano numbers that provides two given ```scala import scala.reflect._ -trait Peano with +trait Peano: type Nat type Zero <: Nat type Succ <: Nat @@ -125,11 +125,11 @@ trait Peano with val Zero: Zero val Succ: SuccExtractor - trait SuccExtractor with + trait SuccExtractor: def apply(nat: Nat): Succ def unapply(nat: Succ): Option[Nat] - given typeTestOfZero: TypeTest[Nat, Zero] + given typeTestOfZero: TypeTest[Nat, Zero] given typeTestOfSucc: TypeTest[Nat, Succ] ``` diff --git a/docs/docs/reference/syntax.md b/docs/docs/reference/syntax.md index 5aa086fc33c5..764844e48042 100644 --- a/docs/docs/reference/syntax.md +++ b/docs/docs/reference/syntax.md @@ -83,6 +83,7 @@ comment ::= ‘/*’ “any sequence of characters; nested comments ar nl ::= “new line character” semi ::= ‘;’ | nl {nl} +colonEol ::= ": at end of line that can start a template body" ``` The lexical analyzer also inserts `indent` and `outdent` tokens that represent regions of indented code [at certain points](../reference/other-new-features-indentation.html) @@ -145,80 +146,79 @@ ClassQualifier ::= ‘[’ id ‘]’ ### Types ```ebnf Type ::= FunType - | HkTypeParamClause ‘=>>’ Type LambdaTypeTree(ps, t) - | FunParamClause ‘=>>’ Type TermLambdaTypeTree(ps, t) + | HkTypeParamClause ‘=>>’ Type + | FunParamClause ‘=>>’ Type | MatchType | InfixType -FunType ::= FunArgTypes (‘=>’ | ‘?=>’) Type Function(ts, t) - | HKTypeParamClause '=>' Type PolyFunction(ps, t) +FunType ::= FunArgTypes (‘=>’ | ‘?=>’) Type + | HKTypeParamClause '=>' Type FunArgTypes ::= InfixType | ‘(’ [ FunArgType {‘,’ FunArgType } ] ‘)’ | FunParamClause FunParamClause ::= ‘(’ TypedFunParam {‘,’ TypedFunParam } ‘)’ TypedFunParam ::= id ‘:’ Type MatchType ::= InfixType `match` <<< TypeCaseClauses >>> -InfixType ::= RefinedType {id [nl] RefinedType} InfixOp(t1, op, t2) -RefinedType ::= AnnotType {[nl | ‘with’] Refinement} RefinedTypeTree(t, ds) -AnnotType ::= SimpleType {Annotation} Annotated(t, annot) +InfixType ::= RefinedType {id [nl] RefinedType} +RefinedType ::= AnnotType {[nl] Refinement} +AnnotType ::= SimpleType {Annotation} -SimpleType ::= SimpleLiteral SingletonTypeTree(l) +SimpleType ::= SimpleLiteral | ‘?’ TypeBounds - | SimpleType1 -SimpleType1 ::= id Ident(name) - | Singleton ‘.’ id Select(t, name) - | Singleton ‘.’ ‘type’ SingletonTypeTree(p) - | ‘(’ Types ‘)’ Tuple(ts) - | Refinement RefinedTypeTree(EmptyTree, refinement) + | id + | Singleton ‘.’ id + | Singleton ‘.’ ‘type’ + | ‘(’ Types ‘)’ + | Refinement | ‘$’ ‘{’ Block ‘}’ - | SimpleType1 TypeArgs AppliedTypeTree(t, args) - | SimpleType1 ‘#’ id Select(t, name) + | SimpleType1 TypeArgs + | SimpleType1 ‘#’ id Singleton ::= SimpleRef | SimpleLiteral | Singleton ‘.’ id -Singletons ::= Singleton { ‘,’ Singleton } + FunArgType ::= Type - | ‘=>’ Type PrefixOp(=>, t) + | ‘=>’ Type ParamType ::= [‘=>’] ParamValueType -ParamValueType ::= Type [‘*’] PostfixOp(t, "*") -TypeArgs ::= ‘[’ Types ‘]’ ts -Refinement ::= <<< [RefineDcl] {semi [RefineDcl]} >>> ds -TypeBounds ::= [‘>:’ Type] [‘<:’ Type] TypeBoundsTree(lo, hi) -TypeParamBounds ::= TypeBounds {‘:’ Type} ContextBounds(typeBounds, tps) +ParamValueType ::= Type [‘*’] +TypeArgs ::= ‘[’ Types ‘]’ +Refinement ::= ‘{’ [RefineDcl] {semi [RefineDcl]} ‘}’ +TypeBounds ::= [‘>:’ Type] [‘<:’ Type] +TypeParamBounds ::= TypeBounds {‘:’ Type} Types ::= Type {‘,’ Type} ``` ### Expressions ```ebnf -Expr ::= FunParams (‘=>’ | ‘?=>’) Expr Function(args, expr), Function(ValDef([implicit], id, TypeTree(), EmptyTree), expr) +Expr ::= FunParams (‘=>’ | ‘?=>’) Expr | Expr1 BlockResult ::= FunParams (‘=>’ | ‘?=>’) Block | Expr1 FunParams ::= Bindings | id | ‘_’ -Expr1 ::= [‘inline’] ‘if’ ‘(’ Expr ‘)’ {nl} Expr [[semi] ‘else’ Expr] If(Parens(cond), thenp, elsep?) - | [‘inline’] ‘if’ Expr ‘then’ Expr [[semi] ‘else’ Expr] If(cond, thenp, elsep?) - | ‘while’ ‘(’ Expr ‘)’ {nl} Expr WhileDo(Parens(cond), body) - | ‘while’ Expr ‘do’ Expr WhileDo(cond, body) - | ‘try’ Expr Catches [‘finally’ Expr] Try(expr, catches, expr?) - | ‘try’ Expr [‘finally’ Expr] Try(expr, Nil, expr?) - | ‘throw’ Expr Throw(expr) - | ‘return’ [Expr] Return(expr?) +Expr1 ::= [‘inline’] ‘if’ ‘(’ Expr ‘)’ {nl} Expr [[semi] ‘else’ Expr] + | [‘inline’] ‘if’ Expr ‘then’ Expr [[semi] ‘else’ Expr] + | ‘while’ ‘(’ Expr ‘)’ {nl} Expr + | ‘while’ Expr ‘do’ Expr + | ‘try’ Expr Catches [‘finally’ Expr] + | ‘try’ Expr [‘finally’ Expr] + | ‘throw’ Expr + | ‘return’ [Expr] | ForExpr - | HkTypeParamClause ‘=>’ Expr PolyFunction(ts, expr) - | [SimpleExpr ‘.’] id ‘=’ Expr Assign(expr, expr) - | SimpleExpr1 ArgumentExprs ‘=’ Expr Assign(expr, expr) + | HkTypeParamClause ‘=>’ Expr + | [SimpleExpr ‘.’] id ‘=’ Expr + | SimpleExpr1 ArgumentExprs ‘=’ Expr | PostfixExpr [Ascription] | ‘inline’ InfixExpr MatchClause -Ascription ::= ‘:’ InfixType Typed(expr, tp) - | ‘:’ Annotation {Annotation} Typed(expr, Annotated(EmptyTree, annot)*) +Ascription ::= ‘:’ InfixType + | ‘:’ Annotation {Annotation} Catches ::= ‘catch’ (Expr | ExprCaseClause) -PostfixExpr ::= InfixExpr [id] PostfixOp(expr, op) +PostfixExpr ::= InfixExpr [id] InfixExpr ::= PrefixExpr - | InfixExpr id [nl] InfixExpr InfixOp(expr, op, expr) + | InfixExpr id [nl] InfixExpr | InfixExpr MatchClause -MatchClause ::= ‘match’ <<< CaseClauses >>> Match(expr, cases) -PrefixExpr ::= [‘-’ | ‘+’ | ‘~’ | ‘!’] SimpleExpr PrefixOp(expr, op) +MatchClause ::= ‘match’ <<< CaseClauses >>> +PrefixExpr ::= [‘-’ | ‘+’ | ‘~’ | ‘!’] SimpleExpr SimpleExpr ::= SimpleRef | Literal | ‘_’ @@ -226,26 +226,24 @@ SimpleExpr ::= SimpleRef | ‘$’ ‘{’ Block ‘}’ | Quoted | quoteId -- only inside splices - | ‘new’ ConstrApp {‘with’ ConstrApp} [TemplateBody] New(constr | templ) - | ‘new’ TemplateBody - | ‘(’ ExprsInParens ‘)’ Parens(exprs) - | SimpleExpr ‘.’ id Select(expr, id) + | ‘new’ ConstrApp {‘with’ ConstrApp} [[colonEol] TemplateBody + | ‘new’ [colonEol] TemplateBody + | ‘(’ ExprsInParens ‘)’ + | SimpleExpr ‘.’ id | SimpleExpr ‘.’ MatchClause - | SimpleExpr TypeArgs TypeApply(expr, args) - | SimpleExpr ArgumentExprs Apply(expr, args) - | SimpleExpr ‘_’ PostfixOp(expr, _) (to be dropped) - | XmlExpr (to be dropped) + | SimpleExpr TypeArgs + | SimpleExpr ArgumentExprs Quoted ::= ‘'’ ‘{’ Block ‘}’ | ‘'’ ‘[’ Type ‘]’ ExprsInParens ::= ExprInParens {‘,’ ExprInParens} -ExprInParens ::= PostfixExpr ‘:’ Type -- normal Expr allows only RefinedType here +ExprInParens ::= PostfixExpr ‘:’ Type | Expr -ParArgumentExprs ::= ‘(’ [‘using’] ExprsInParens ‘)’ exprs - | ‘(’ [ExprsInParens ‘,’] PostfixExpr ‘:’ ‘_’ ‘*’ ‘)’ exprs :+ Typed(expr, Ident(wildcardStar)) +ParArgumentExprs ::= ‘(’ [‘using’] ExprsInParens ‘)’ + | ‘(’ [ExprsInParens ‘,’] PostfixExpr ‘:’ ‘_’ ‘*’ ‘)’ ArgumentExprs ::= ParArgumentExprs | BlockExpr -BlockExpr ::= <<< (CaseClauses | Block) >>> -Block ::= {BlockStat semi} [BlockResult] Block(stats, expr?) +BlockExpr ::= ‘{’ (CaseClauses | Block) ‘}’ +Block ::= {BlockStat semi} [BlockResult] BlockStat ::= Import | {Annotation {nl}} [‘implicit’ | ‘lazy’] Def | {Annotation {nl}} {LocalModifier} TmplDef @@ -253,31 +251,29 @@ BlockStat ::= Import | Expr1 | EndMarker -ForExpr ::= ‘for’ (‘(’ Enumerators ‘)’ | ‘{’ Enumerators ‘}’) ForYield(enums, expr) - {nl} [‘yield’] Expr - | ‘for’ Enumerators (‘do’ Expr | ‘yield’ Expr) ForDo(enums, expr) +ForExpr ::= ‘for’ (‘(’ Enumerators ‘)’ | ‘{’ Enumerators ‘}’) {nl} [‘yield’] Expr + | ‘for’ Enumerators (‘do’ Expr | ‘yield’ Expr) Enumerators ::= Generator {semi Enumerator | Guard} Enumerator ::= Generator | Guard - | Pattern1 ‘=’ Expr GenAlias(pat, expr) -Generator ::= [‘case’] Pattern1 ‘<-’ Expr GenFrom(pat, expr) + | Pattern1 ‘=’ Expr +Generator ::= [‘case’] Pattern1 ‘<-’ Expr Guard ::= ‘if’ PostfixExpr -CaseClauses ::= CaseClause { CaseClause } Match(EmptyTree, cases) -CaseClause ::= ‘case’ Pattern [Guard] ‘=>’ Block CaseDef(pat, guard?, block) // block starts at => +CaseClauses ::= CaseClause { CaseClause } +CaseClause ::= ‘case’ Pattern [Guard] ‘=>’ Block ExprCaseClause ::= ‘case’ Pattern [Guard] ‘=>’ Expr TypeCaseClauses ::= TypeCaseClause { TypeCaseClause } TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [nl] -Pattern ::= Pattern1 { ‘|’ Pattern1 } Alternative(pats) -Pattern1 ::= Pattern2 [‘:’ RefinedType] Bind(name, Typed(Ident(wildcard), tpe)) -Pattern2 ::= [id ‘@’] InfixPattern Bind(name, pat) -InfixPattern ::= SimplePattern { id [nl] SimplePattern } InfixOp(pat, op, pat) -SimplePattern ::= PatVar Ident(wildcard) - | Literal Bind(name, Ident(wildcard)) - | ‘(’ [Patterns] ‘)’ Parens(pats) Tuple(pats) +Pattern ::= Pattern1 { ‘|’ Pattern1 } +Pattern1 ::= Pattern2 [‘:’ RefinedType] +Pattern2 ::= [id ‘@’] InfixPattern +InfixPattern ::= SimplePattern { id [nl] SimplePattern } +SimplePattern ::= PatVar + | Literal + | ‘(’ [Patterns] ‘)’ | Quoted - | XmlPattern (to be dropped) | SimplePattern1 [TypeArgs] [ArgumentPatterns] | ‘given’ RefinedType SimplePattern1 ::= SimpleRef @@ -285,15 +281,14 @@ SimplePattern1 ::= SimpleRef PatVar ::= varid | ‘_’ Patterns ::= Pattern {‘,’ Pattern} -ArgumentPatterns ::= ‘(’ [Patterns] ‘)’ Apply(fn, pats) +ArgumentPatterns ::= ‘(’ [Patterns] ‘)’ | ‘(’ [Patterns ‘,’] Pattern2 ‘:’ ‘_’ ‘*’ ‘)’ ``` ### Type and Value Parameters ```ebnf ClsTypeParamClause::= ‘[’ ClsTypeParam {‘,’ ClsTypeParam} ‘]’ -ClsTypeParam ::= {Annotation} [‘+’ | ‘-’] TypeDef(Modifiers, name, tparams, bounds) - id [HkTypeParamClause] TypeParamBounds Bound(below, above, context) +ClsTypeParam ::= {Annotation} [‘+’ | ‘-’] id [HkTypeParamClause] TypeParamBounds DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’ DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds @@ -302,28 +297,26 @@ TypTypeParamClause::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’ TypTypeParam ::= {Annotation} id [HkTypeParamClause] TypeBounds HkTypeParamClause ::= ‘[’ HkTypeParam {‘,’ HkTypeParam} ‘]’ -HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (id [HkTypeParamClause] | ‘_’) - TypeBounds +HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (id [HkTypeParamClause] | ‘_’) TypeBounds ClsParamClauses ::= {ClsParamClause} [[nl] ‘(’ [‘implicit’] ClsParams ‘)’] ClsParamClause ::= [nl] ‘(’ ClsParams ‘)’ | [nl] ‘(’ ‘using’ (ClsParams | Types) ‘)’ ClsParams ::= ClsParam {‘,’ ClsParam} -ClsParam ::= {Annotation} ValDef(mods, id, tpe, expr) -- point of mods on val/var - [{Modifier} (‘val’ | ‘var’) | ‘inline’] Param +ClsParam ::= {Annotation} [{Modifier} (‘val’ | ‘var’) | ‘inline’] Param Param ::= id ‘:’ ParamType [‘=’ Expr] DefParamClauses ::= {DefParamClause} [[nl] ‘(’ [‘implicit’] DefParams ‘)’] DefParamClause ::= [nl] ‘(’ DefParams ‘)’ | UsingParamClause UsingParamClause ::= [nl] ‘(’ ‘using’ (DefParams | Types) ‘)’ DefParams ::= DefParam {‘,’ DefParam} -DefParam ::= {Annotation} [‘inline’] Param ValDef(mods, id, tpe, expr) -- point of mods at id. +DefParam ::= {Annotation} [‘inline’] Param ``` ### Bindings and Imports ```ebnf Bindings ::= ‘(’ [Binding {‘,’ Binding}] ‘)’ -Binding ::= (id | ‘_’) [‘:’ Type] ValDef(_, id, tpe, EmptyTree) +Binding ::= (id | ‘_’) [‘:’ Type] Modifier ::= LocalModifier | AccessModifier @@ -339,10 +332,10 @@ LocalModifier ::= ‘abstract’ AccessModifier ::= (‘private’ | ‘protected’) [AccessQualifier] AccessQualifier ::= ‘[’ id ‘]’ -Annotation ::= ‘@’ SimpleType1 {ParArgumentExprs} Apply(tpe, args) +Annotation ::= ‘@’ SimpleType1 {ParArgumentExprs} Import ::= ‘import’ ImportExpr {‘,’ ImportExpr} -ImportExpr ::= SimpleRef {‘.’ id} ‘.’ ImportSpec Import(expr, sels) +ImportExpr ::= SimpleRef {‘.’ id} ‘.’ ImportSpec ImportSpec ::= id | ‘_’ | ‘given’ @@ -365,12 +358,11 @@ RefineDcl ::= ‘val’ ValDcl | ‘type’ {nl} TypeDcl Dcl ::= RefineDcl | ‘var’ VarDcl -ValDcl ::= ids ‘:’ Type PatDef(_, ids, tpe, EmptyTree) -VarDcl ::= ids ‘:’ Type PatDef(_, ids, tpe, EmptyTree) -DefDcl ::= DefSig ‘:’ Type DefDef(_, name, tparams, vparamss, tpe, EmptyTree) +ValDcl ::= ids ‘:’ Type +VarDcl ::= ids ‘:’ Type +DefDcl ::= DefSig ‘:’ Type DefSig ::= id [DefTypeParamClause] DefParamClauses -TypeDcl ::= id [TypeParamClause] {FunParamClause} TypeBounds TypeDefTree(_, name, tparams, bound - [‘=’ Type] +TypeDcl ::= id [TypeParamClause] {FunParamClause} TypeBounds [‘=’ Type] Def ::= ‘val’ PatDef | ‘var’ VarDef @@ -378,38 +370,37 @@ Def ::= ‘val’ PatDef | ‘type’ {nl} TypeDcl | TmplDef PatDef ::= ids [‘:’ Type] ‘=’ Expr - | Pattern2 [‘:’ Type] ‘=’ Expr PatDef(_, pats, tpe?, expr) + | Pattern2 [‘:’ Type] ‘=’ Expr VarDef ::= PatDef | ids ‘:’ Type ‘=’ ‘_’ -DefDef ::= DefSig [‘:’ Type] ‘=’ Expr DefDef(_, name, tparams, vparamss, tpe, expr) - | ‘this’ DefParamClause DefParamClauses ‘=’ ConstrExpr DefDef(_, , Nil, vparamss, EmptyTree, expr | Block) +DefDef ::= DefSig [‘:’ Type] ‘=’ Expr + | ‘this’ DefParamClause DefParamClauses ‘=’ ConstrExpr TmplDef ::= ([‘case’] ‘class’ | ‘trait’) ClassDef | [‘case’] ‘object’ ObjectDef | ‘enum’ EnumDef | ‘given’ GivenDef -ClassDef ::= id ClassConstr [Template] ClassDef(mods, name, tparams, templ) -ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsParamClauses with DefDef(_, , Nil, vparamss, EmptyTree, EmptyTree) as first stat +ClassDef ::= id ClassConstr [Template] +ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsParamClauses ConstrMods ::= {Annotation} [AccessModifier] -ObjectDef ::= id [Template] ModuleDef(mods, name, template) // no constructor -EnumDef ::= id ClassConstr InheritClauses EnumBody -GivenDef ::= [GivenSig] (AnnotType [‘=’ Expr] | ConstrApps TemplateBody) +ObjectDef ::= id [Template] +EnumDef ::= id ClassConstr InheritClauses [colonEol] EnumBody +GivenDef ::= [GivenSig] (Type [‘=’ Expr] | StructuralInstance) GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘:’ -- one of `id`, `DefParamClause`, `UsingParamClause` must be present +StructuralInstance ::= ConstrApp {‘with’ ConstrApp} ‘with’ TemplateBody Extension ::= ‘extension’ [DefTypeParamClause] ‘(’ DefParam ‘)’ {UsingParamClause}] ExtMethods -ExtMethods ::= ExtMethod | [nl] <<< ExtMethod {semi ExtMethod >>> +ExtMethods ::= ExtMethod | [nl] ‘{’ ExtMethod {semi ExtMethod ‘}’ ExtMethod ::= {Annotation [nl]} {Modifier} ‘def’ DefDef -Template ::= InheritClauses [TemplateBody] Template(constr, parents, self, stats) +Template ::= InheritClauses [colonEol] [TemplateBody] InheritClauses ::= [‘extends’ ConstrApps] [‘derives’ QualId {‘,’ QualId}] ConstrApps ::= ConstrApp ({‘,’ ConstrApp} | {‘with’ ConstrApp}) -ConstrApp ::= SimpleType1 {Annotation} {ParArgumentExprs} Apply(tp, args) +ConstrApp ::= SimpleType1 {Annotation} {ParArgumentExprs} ConstrExpr ::= SelfInvocation | <<< SelfInvocation {semi BlockStat} >>> SelfInvocation ::= ‘this’ ArgumentExprs {ArgumentExprs} -TemplateBody ::= [nl | ‘with’] <<< [SelfType] TemplateStats >>> - | ‘with’ SelfType indent TemplateStats outdent -TemplateStats ::= TemplateStat {semi TemplateStat} +TemplateBody ::= [nl] ‘{’ [SelfType] TemplateStat {semi TemplateStat} ‘}’ TemplateStat ::= Import | Export | {Annotation [nl]} {Modifier} Def @@ -418,12 +409,10 @@ TemplateStat ::= Import | Expr1 | EndMarker | -SelfType ::= id [‘:’ InfixType] ‘=>’ ValDef(_, name, tpt, _) +SelfType ::= id [‘:’ InfixType] ‘=>’ | ‘this’ ‘:’ InfixType ‘=>’ -EnumBody ::= [nl | ‘with’] <<< [SelfType] EnumStats >>> - | ‘with’ [SelfType] indent EnumStats outdent -EnumStats ::= EnumStat {semi EnumStat} +EnumBody ::= [nl] ‘{’ [SelfType] EnumStat {semi EnumStat} ‘}’ EnumStat ::= TemplateStat | {Annotation [nl]} {Modifier} EnumCase EnumCase ::= ‘case’ (id ClassConstr [‘extends’ ConstrApps]] | ids) @@ -437,8 +426,8 @@ TopStat ::= Import | PackageObject | EndMarker | -Packaging ::= ‘package’ QualId [nl| ‘with’] <<< TopStats >>> Package(qid, stats) -PackageObject ::= ‘package’ ‘object’ ObjectDef object with package in mods. +Packaging ::= ‘package’ QualId [nl | colonEol] ‘{’ TopStats‘}’ +PackageObject ::= ‘package’ ‘object’ ObjectDef -CompilationUnit ::= {‘package’ QualId semi} TopStats Package(qid, stats) +CompilationUnit ::= {‘package’ QualId semi} TopStats ``` diff --git a/docs/docs/release-notes/syntax-changes-0.22.md b/docs/docs/release-notes/syntax-changes-0.22.md index cc5cf45ebf1e..64207d72e9d1 100644 --- a/docs/docs/release-notes/syntax-changes-0.22.md +++ b/docs/docs/release-notes/syntax-changes-0.22.md @@ -94,7 +94,7 @@ class Str(str: String) extends Text: class Append(txt1: Text, txt2: Text) extends Text: def toString = txt1 ++ txt2 -object Empty extends Text with +object Empty extends Text: def toString = "" extension on (t: Text): diff --git a/library/src/scala/Conversion.scala b/library/src/scala/Conversion.scala index d847ff900d32..bb66a068e09c 100644 --- a/library/src/scala/Conversion.scala +++ b/library/src/scala/Conversion.scala @@ -19,5 +19,5 @@ package scala * from two to one. */ @java.lang.FunctionalInterface -abstract class Conversion[-T, +U] extends Function1[T, U] with +abstract class Conversion[-T, +U] extends Function1[T, U]: def apply(x: T): U diff --git a/library/src/scala/Selectable.scala b/library/src/scala/Selectable.scala index f84293c3c182..f89102ae4802 100644 --- a/library/src/scala/Selectable.scala +++ b/library/src/scala/Selectable.scala @@ -23,7 +23,7 @@ package scala */ trait Selectable extends Any -object Selectable with +object Selectable: /* Scala 2 compat + allowing for cross-compilation: * enable scala.reflect.Selectable.reflectiveSelectable when there is an * import scala.language.reflectiveCalls in scope. diff --git a/library/src/scala/compiletime/ops/any.scala b/library/src/scala/compiletime/ops/any.scala index c791ced2b03e..2119188fcc30 100644 --- a/library/src/scala/compiletime/ops/any.scala +++ b/library/src/scala/compiletime/ops/any.scala @@ -1,7 +1,7 @@ package scala.compiletime package ops -object any with +object any: /** Equality comparison of two singleton types. * ```scala * val eq1: 1 == 1 = true diff --git a/library/src/scala/compiletime/ops/boolean.scala b/library/src/scala/compiletime/ops/boolean.scala index 0b2f1b94d204..dd050c8ad57a 100644 --- a/library/src/scala/compiletime/ops/boolean.scala +++ b/library/src/scala/compiletime/ops/boolean.scala @@ -1,7 +1,7 @@ package scala.compiletime package ops -object boolean with +object boolean: /** Negation of a `Boolean` singleton type. * ```scala diff --git a/library/src/scala/compiletime/ops/int.scala b/library/src/scala/compiletime/ops/int.scala index e603c307d45c..cfcfd439e7eb 100644 --- a/library/src/scala/compiletime/ops/int.scala +++ b/library/src/scala/compiletime/ops/int.scala @@ -1,7 +1,7 @@ package scala.compiletime package ops -object int with +object int: /** Addition of two `Int` singleton types. * ```scala * val sum: 2 + 2 = 4 diff --git a/library/src/scala/compiletime/ops/string.scala b/library/src/scala/compiletime/ops/string.scala index 697613dd715c..77aa8a1329f4 100644 --- a/library/src/scala/compiletime/ops/string.scala +++ b/library/src/scala/compiletime/ops/string.scala @@ -1,7 +1,7 @@ package scala.compiletime package ops -object string with +object string: /** Concatenation of two `String` singleton types. * ```scala * val hello: "hello " + "world" = "hello world" diff --git a/library/src/scala/compiletime/testing/ErrorKind.scala b/library/src/scala/compiletime/testing/ErrorKind.scala index 5ccba0e1af2c..c7e38ae22d83 100644 --- a/library/src/scala/compiletime/testing/ErrorKind.scala +++ b/library/src/scala/compiletime/testing/ErrorKind.scala @@ -3,6 +3,6 @@ package scala.compiletime.testing /** An error can be either a parse-time or a typecheck-time */ sealed trait ErrorKind // This should be an enum but currently, Dotty lib fails to // compile with an obscure error. -object ErrorKind with +object ErrorKind: case object Parser extends ErrorKind case object Typer extends ErrorKind diff --git a/library/src/scala/quoted/ExprMap.scala b/library/src/scala/quoted/ExprMap.scala index d7931044a0e8..6f36a3a473e3 100644 --- a/library/src/scala/quoted/ExprMap.scala +++ b/library/src/scala/quoted/ExprMap.scala @@ -1,6 +1,6 @@ package scala.quoted -trait ExprMap with +trait ExprMap: /** Map an expression `e` with a type `T` */ def transform[T](e: Expr[T])(using Type[T])(using Quotes): Expr[T] diff --git a/library/src/scala/quoted/Exprs.scala b/library/src/scala/quoted/Exprs.scala index 4121af24390a..7e71ab411055 100644 --- a/library/src/scala/quoted/Exprs.scala +++ b/library/src/scala/quoted/Exprs.scala @@ -1,6 +1,6 @@ package scala.quoted -object Exprs with +object Exprs: /** Matches literal sequence of literal constant value expressions and return a sequence of values. * diff --git a/library/src/scala/quoted/Type.scala b/library/src/scala/quoted/Type.scala index fbf2513c379c..58b4cd63b827 100644 --- a/library/src/scala/quoted/Type.scala +++ b/library/src/scala/quoted/Type.scala @@ -3,13 +3,13 @@ package scala.quoted import scala.annotation.compileTimeOnly /** Type (or type constructor) `T` needed contextually when using `T` in a quoted expression `'{... T ...}` */ -abstract class Type[T <: AnyKind] private[scala] with +abstract class Type[T <: AnyKind] private[scala]: /** The type represented `Type` */ type Underlying = T end Type /** Methods to interact with the current `Type[T]` in scope */ -object Type with +object Type: /** Show a source code like representation of this type without syntax highlight */ def show[T <: AnyKind](using Type[T])(using Quotes): String = diff --git a/library/src/scala/quoted/runtime/Expr.scala b/library/src/scala/quoted/runtime/Expr.scala index 0ab4e100197d..2ca63410263e 100644 --- a/library/src/scala/quoted/runtime/Expr.scala +++ b/library/src/scala/quoted/runtime/Expr.scala @@ -4,7 +4,7 @@ package runtime import scala.annotation.{Annotation, compileTimeOnly} @compileTimeOnly("Illegal reference to `scala.quoted.runtime.Expr`") -object Expr with +object Expr: /** A term quote is desugared by the compiler into a call to this method * diff --git a/library/src/scala/quoted/runtime/QuoteMatching.scala b/library/src/scala/quoted/runtime/QuoteMatching.scala index 0401a30a2704..853e119955de 100644 --- a/library/src/scala/quoted/runtime/QuoteMatching.scala +++ b/library/src/scala/quoted/runtime/QuoteMatching.scala @@ -3,7 +3,7 @@ package scala.quoted.runtime import scala.quoted.{Expr, Type} /** Part of the Quotes interface that needs to be implemented by the compiler but is not visible to users */ -trait QuoteMatching with +trait QuoteMatching: val ExprMatch: ExprMatchModule diff --git a/library/src/scala/quoted/runtime/QuoteUnpickler.scala b/library/src/scala/quoted/runtime/QuoteUnpickler.scala index d26161deff95..2d8ef54eb9e6 100644 --- a/library/src/scala/quoted/runtime/QuoteUnpickler.scala +++ b/library/src/scala/quoted/runtime/QuoteUnpickler.scala @@ -3,7 +3,7 @@ package scala.quoted.runtime import scala.quoted.{Quotes, Expr, Type} /** Part of the Quotes interface that needs to be implemented by the compiler but is not visible to users */ -trait QuoteUnpickler with +trait QuoteUnpickler: /** Unpickle `repr` which represents a pickled `Expr` tree, * replacing splice nodes with `holes` diff --git a/library/src/scala/reflect/Enum.scala b/library/src/scala/reflect/Enum.scala index 80b48b6e1ed4..92efa34cf430 100644 --- a/library/src/scala/reflect/Enum.scala +++ b/library/src/scala/reflect/Enum.scala @@ -1,7 +1,7 @@ package scala.reflect /** A base trait of all Scala enum definitions */ -@annotation.transparentTrait trait Enum extends Any, Product, Serializable with +@annotation.transparentTrait trait Enum extends Any, Product, Serializable: /** A number uniquely identifying a case of an enum */ def ordinal: Int diff --git a/library/src/scala/reflect/Selectable.scala b/library/src/scala/reflect/Selectable.scala index 44f4acf40ed4..a9606fd7b45b 100644 --- a/library/src/scala/reflect/Selectable.scala +++ b/library/src/scala/reflect/Selectable.scala @@ -8,7 +8,7 @@ package scala.reflect * In Scala.js, it is implemented using a separate Scala.js-specific * mechanism, since Java reflection is not available. */ -trait Selectable extends scala.Selectable with +trait Selectable extends scala.Selectable: /** The value from which structural members are selected. * By default this is the Selectable instance itself, but it can @@ -39,7 +39,7 @@ trait Selectable extends scala.Selectable with ensureAccessible(mth) mth.invoke(selectedValue, args.asInstanceOf[Seq[AnyRef]]: _*) -object Selectable with +object Selectable: /** An implicit conversion that turns a value into a Selectable * such that structural selections are performed on that value. diff --git a/library/src/scala/reflect/TypeTest.scala b/library/src/scala/reflect/TypeTest.scala index c231ae5d9aa2..7d3cc9908cc4 100644 --- a/library/src/scala/reflect/TypeTest.scala +++ b/library/src/scala/reflect/TypeTest.scala @@ -10,7 +10,7 @@ package scala.reflect * then a given instance of `TypeTest[S, T]` is summoned and used to perform the test. */ @scala.annotation.implicitNotFound(msg = "No TypeTest available for [${S}, ${T}]") -trait TypeTest[-S, T] extends Serializable with +trait TypeTest[-S, T] extends Serializable: /** A TypeTest[S, T] can serve as an extractor that matches only S of type T. * @@ -22,7 +22,7 @@ trait TypeTest[-S, T] extends Serializable with */ def unapply(x: S): Option[x.type & T] -object TypeTest with +object TypeTest: /** Trivial type test that always succeeds */ def identity[T]: TypeTest[T, T] = Some(_) diff --git a/library/src/scala/runtime/EnumValue.scala b/library/src/scala/runtime/EnumValue.scala index 0ced056b2dd0..5eb078a8c34b 100644 --- a/library/src/scala/runtime/EnumValue.scala +++ b/library/src/scala/runtime/EnumValue.scala @@ -1,6 +1,6 @@ package scala.runtime -@annotation.transparentTrait trait EnumValue extends Product, Serializable with +@annotation.transparentTrait trait EnumValue extends Product, Serializable: override def canEqual(that: Any) = this eq that.asInstanceOf[AnyRef] override def productArity: Int = 0 override def productElement(n: Int): Any = diff --git a/library/src/scala/runtime/Scala3RunTime.scala b/library/src/scala/runtime/Scala3RunTime.scala index 2f54476184ff..fa141628ceec 100644 --- a/library/src/scala/runtime/Scala3RunTime.scala +++ b/library/src/scala/runtime/Scala3RunTime.scala @@ -1,6 +1,6 @@ package scala.runtime -object Scala3RunTime with +object Scala3RunTime: // Called by inline def assert's. Extracted to minimize the bytecode size at call site. diff --git a/library/src/scala/runtime/stdLibPatches/Predef.scala b/library/src/scala/runtime/stdLibPatches/Predef.scala index b71f8717b913..d811d7d2e3fb 100644 --- a/library/src/scala/runtime/stdLibPatches/Predef.scala +++ b/library/src/scala/runtime/stdLibPatches/Predef.scala @@ -1,6 +1,6 @@ package scala.runtime.stdLibPatches -object Predef with +object Predef: import compiletime.summonFrom inline def assert(inline assertion: Boolean, inline message: => Any): Unit = diff --git a/library/src/scala/runtime/stdLibPatches/language.scala b/library/src/scala/runtime/stdLibPatches/language.scala index cf02c0b67f7e..91f1c88b977a 100644 --- a/library/src/scala/runtime/stdLibPatches/language.scala +++ b/library/src/scala/runtime/stdLibPatches/language.scala @@ -2,7 +2,7 @@ package scala.runtime.stdLibPatches /** Scala 3 additions and replacements to the `scala.language` object. */ -object language with +object language: /** The experimental object contains features that have been recently added but have not * been thoroughly tested in production yet. @@ -16,7 +16,7 @@ object language with * * @group experimental */ - object experimental with + object experimental: /* Experimental support for richer dependent types (disabled for now) * One can still run the compiler with support for parsing singleton applications diff --git a/stdlib-bootstrapped-tasty-tests/test/BootstrappedStdLibTASYyTest.scala b/stdlib-bootstrapped-tasty-tests/test/BootstrappedStdLibTASYyTest.scala index 43f365410fc3..ef004baa191a 100644 --- a/stdlib-bootstrapped-tasty-tests/test/BootstrappedStdLibTASYyTest.scala +++ b/stdlib-bootstrapped-tasty-tests/test/BootstrappedStdLibTASYyTest.scala @@ -12,7 +12,7 @@ import scala.quoted._ import java.io.File.pathSeparator import java.io.File.separator -class BootstrappedStdLibTASYyTest with +class BootstrappedStdLibTASYyTest: import BootstrappedStdLibTASYyTest._ @@ -88,7 +88,7 @@ class BootstrappedStdLibTASYyTest with end BootstrappedStdLibTASYyTest -object BootstrappedStdLibTASYyTest with +object BootstrappedStdLibTASYyTest: def scalaLibJarPath = System.getProperty("dotty.scala.library") def scalaLibClassesPath = diff --git a/stdlib-bootstrapped/test/Main.scala b/stdlib-bootstrapped/test/Main.scala index b43a640c153c..1dad89eceffc 100644 --- a/stdlib-bootstrapped/test/Main.scala +++ b/stdlib-bootstrapped/test/Main.scala @@ -1,9 +1,9 @@ package hello -enum Color with +enum Color: case Red, Green, Blue -object HelloWorld with +object HelloWorld: def main(args: Array[String]): Unit = { println("hello dotty.superbootstrapped!") println(Color.Red) diff --git a/tests/bench/string-interpolation-macro/Test.scala b/tests/bench/string-interpolation-macro/Test.scala index 094462aa175b..e32eeea2fef7 100644 --- a/tests/bench/string-interpolation-macro/Test.scala +++ b/tests/bench/string-interpolation-macro/Test.scala @@ -1,4 +1,4 @@ import Macro._ -class Test with +class Test: def test: String = x"a${1}b${2}c${3}d${4}e${5}f" diff --git a/tests/disabled/pos/i8311.scala b/tests/disabled/pos/i8311.scala index 0d4423d93fb8..eeecd97a7e7e 100644 --- a/tests/disabled/pos/i8311.scala +++ b/tests/disabled/pos/i8311.scala @@ -1,12 +1,12 @@ -trait Show[O] with +trait Show[O]: extension (o: O) def show: String class Box[A] class Foo -object test with +object test: given box[A](using Show[A]): Show[Box[A]] = _.toString given foo: Show[Foo] = _.toString diff --git a/tests/neg-custom-args/explicit-nulls/byname-nullables.scala b/tests/neg-custom-args/explicit-nulls/byname-nullables.scala index ada838b269f6..4da2659bbde6 100644 --- a/tests/neg-custom-args/explicit-nulls/byname-nullables.scala +++ b/tests/neg-custom-args/explicit-nulls/byname-nullables.scala @@ -1,4 +1,4 @@ -object Test1 with +object Test1: def f(x: String) = x ++ x @@ -9,7 +9,7 @@ object Test1 with else x -object Test2 with +object Test2: def f(x: => String) = x ++ x @@ -19,7 +19,7 @@ object Test2 with if x != null then f(x) // error: f is call-by-name else x -object Test3 with +object Test3: def f(x: String, y: String) = x @@ -31,7 +31,7 @@ object Test3 with if x != null then f(x, 1) // OK: not-null check successfully dropped else x -object Test4 with +object Test4: def f(x: String, y: String) = x @@ -43,7 +43,7 @@ object Test4 with if x != null then f(identity(x), 1) // error: dropping not null check fails typing else x -object Test5 with +object Test5: import compiletime.byName def f(x: String, y: String) = x @@ -56,7 +56,7 @@ object Test5 with if x != null then f(byName(identity(x)), 1) // OK, byName avoids the flow typing else x -object Test6 with +object Test6: def f(x: String, y: String) = x @@ -68,7 +68,7 @@ object Test6 with if x != null then f(x, 1) // error: dropping not null check typechecks OK, but gives incompatible result type else x -object Test7 with +object Test7: import compiletime.byName def f(x: String, y: String) = x diff --git a/tests/neg-custom-args/explicit-nulls/byname-nullables1.scala b/tests/neg-custom-args/explicit-nulls/byname-nullables1.scala index eb28a5af96c0..a1c1924c545e 100644 --- a/tests/neg-custom-args/explicit-nulls/byname-nullables1.scala +++ b/tests/neg-custom-args/explicit-nulls/byname-nullables1.scala @@ -1,7 +1,7 @@ def f(op: => Boolean): Unit = () def f(op: Int): Unit = () -class C with +class C: var fld: String | Null = null def test() = diff --git a/tests/neg-custom-args/fatal-warnings/enum-variance.scala b/tests/neg-custom-args/fatal-warnings/enum-variance.scala index b342a28091f2..efe0dbbc6cdd 100644 --- a/tests/neg-custom-args/fatal-warnings/enum-variance.scala +++ b/tests/neg-custom-args/fatal-warnings/enum-variance.scala @@ -1,10 +1,10 @@ -enum View[-T] with +enum View[-T]: case Refl(f: T => T) // error: enum case Refl requires explicit declaration of type T enum ExplicitView[-T]: // desugared version of View case Refl[-T](f: T => T) extends ExplicitView[T] // error: contravariant type T occurs in covariant position -enum InvariantView[-T, +U] extends (T => U) with +enum InvariantView[-T, +U] extends (T => U): case Refl[T](f: T => T) extends InvariantView[T, T] final def apply(t: T): U = this match diff --git a/tests/neg-custom-args/fatal-warnings/i8781b.scala b/tests/neg-custom-args/fatal-warnings/i8781b.scala index ebd3e02d42f8..a30b0e5249c9 100644 --- a/tests/neg-custom-args/fatal-warnings/i8781b.scala +++ b/tests/neg-custom-args/fatal-warnings/i8781b.scala @@ -1,4 +1,4 @@ -object Test with +object Test: println((3: Boolean | Int).isInstanceOf[Boolean]) diff --git a/tests/neg-custom-args/fatal-warnings/opaque-match.scala b/tests/neg-custom-args/fatal-warnings/opaque-match.scala index 8f167932406a..f48a11168274 100644 --- a/tests/neg-custom-args/fatal-warnings/opaque-match.scala +++ b/tests/neg-custom-args/fatal-warnings/opaque-match.scala @@ -1,6 +1,6 @@ case class C() -object O with +object O: opaque type T <: C = C val x: T = C() (??? : Any) match @@ -17,7 +17,7 @@ def Test[T] = (??? : Any) match case _: List[O.T] => ??? // error (??? : Any) match - case _: List[O.T @unchecked] => ??? // OK + case _: List[O.T @unchecked] => ??? // OK (??? : Any) match case _: List[T] => ??? // error diff --git a/tests/neg-custom-args/fatal-warnings/supertraits.scala b/tests/neg-custom-args/fatal-warnings/supertraits.scala index 039c2713a9d4..9337e2f925a3 100644 --- a/tests/neg-custom-args/fatal-warnings/supertraits.scala +++ b/tests/neg-custom-args/fatal-warnings/supertraits.scala @@ -4,7 +4,7 @@ trait S case object a extends S, TA, TB case object b extends S, TA, TB -object Test with +object Test: def choose0[X](x: X, y: X): X = x def choose1[X <: TA](x: X, y: X): X = x diff --git a/tests/neg-custom-args/infix.scala b/tests/neg-custom-args/infix.scala index cc77f40d24d4..f6f3053087dd 100644 --- a/tests/neg-custom-args/infix.scala +++ b/tests/neg-custom-args/infix.scala @@ -1,11 +1,11 @@ // Compile with -strict -Xfatal-warnings -deprecation -class C with +class C: infix def op(x: Int): Int = ??? def meth(x: Int): Int = ??? def matching(x: Int => Int) = ??? def +(x: Int): Int = ??? -object C with +object C: given AnyRef with extension (x: C) infix def iop (y: Int) = ??? diff --git a/tests/neg-macros/BigFloat/BigFloatFromDigitsImpl_1.scala b/tests/neg-macros/BigFloat/BigFloatFromDigitsImpl_1.scala index 093aa33c682d..a1ecc31b776e 100644 --- a/tests/neg-macros/BigFloat/BigFloatFromDigitsImpl_1.scala +++ b/tests/neg-macros/BigFloat/BigFloatFromDigitsImpl_1.scala @@ -3,7 +3,7 @@ import language.experimental.genericNumberLiterals import scala.util.FromDigits import scala.quoted._ -object BigFloatFromDigitsImpl with +object BigFloatFromDigitsImpl: def apply(digits: Expr[String])(using Quotes): Expr[BigFloat] = digits.value match case Some(ds) => diff --git a/tests/neg-macros/GenericNumLits/EvenFromDigitsImpl_1.scala b/tests/neg-macros/GenericNumLits/EvenFromDigitsImpl_1.scala index 80e2e80ea4e9..1d2e484daa5d 100644 --- a/tests/neg-macros/GenericNumLits/EvenFromDigitsImpl_1.scala +++ b/tests/neg-macros/GenericNumLits/EvenFromDigitsImpl_1.scala @@ -3,7 +3,7 @@ import scala.util.FromDigits import scala.quoted._ import Even._ -object EvenFromDigitsImpl with +object EvenFromDigitsImpl: def apply(digits: Expr[String])(using Quotes): Expr[Even] = digits.value match { case Some(ds) => val ev = diff --git a/tests/neg-macros/i9972b/Test_2.scala b/tests/neg-macros/i9972b/Test_2.scala index 85c50e1880ad..1f94ccf18ee8 100644 --- a/tests/neg-macros/i9972b/Test_2.scala +++ b/tests/neg-macros/i9972b/Test_2.scala @@ -1,5 +1,5 @@ class T[A] -object T with +object T: implicit inline def derived[A]: T[A] = new T[A] diff --git a/tests/neg-with-compiler/GenericNumLits/EvenFromDigitsImpl_1.scala b/tests/neg-with-compiler/GenericNumLits/EvenFromDigitsImpl_1.scala index 80e2e80ea4e9..1d2e484daa5d 100644 --- a/tests/neg-with-compiler/GenericNumLits/EvenFromDigitsImpl_1.scala +++ b/tests/neg-with-compiler/GenericNumLits/EvenFromDigitsImpl_1.scala @@ -3,7 +3,7 @@ import scala.util.FromDigits import scala.quoted._ import Even._ -object EvenFromDigitsImpl with +object EvenFromDigitsImpl: def apply(digits: Expr[String])(using Quotes): Expr[Even] = digits.value match { case Some(ds) => val ev = diff --git a/tests/neg/abstract-givens.scala b/tests/neg/abstract-givens.scala index fbfb1ba2adbe..5aa5bdee88e3 100644 --- a/tests/neg/abstract-givens.scala +++ b/tests/neg/abstract-givens.scala @@ -1,9 +1,9 @@ -trait T with +trait T: given x: Int given y(using Int): String = summon[Int].toString given z[T](using T): List[T] -object Test extends T with +object Test extends T: given x: Int = 22 given y(using Int): String = summon[Int].toString * 22 // error given z[T](using T): Seq[T] = List(summon[T]) // error diff --git a/tests/neg/abstract-inline-val.scala b/tests/neg/abstract-inline-val.scala index 4aa3ede2b578..1bcca078ad52 100644 --- a/tests/neg/abstract-inline-val.scala +++ b/tests/neg/abstract-inline-val.scala @@ -1,4 +1,4 @@ -trait C with +trait C: inline def x: Int inline val y: Int diff --git a/tests/neg/ambiref.scala b/tests/neg/ambiref.scala index 95dc06e1573f..e7a5d5efbd7e 100644 --- a/tests/neg/ambiref.scala +++ b/tests/neg/ambiref.scala @@ -1,43 +1,43 @@ -object test1 with +object test1: - class C with + class C: val x = 0 - object Test with + object Test: val x = 1 - class D extends C with + class D extends C: println(x) // error - new C with + new C: println(x) // error -object test2 with +object test2: def c(y: Float) = - class D with + class D: val y = 2 - new D with + new D: println(y) // error -object test3 with +object test3: def c(y: Float) = - class D with + class D: val y = 2 - class E extends D with - class F with + class E extends D: + class F: println(y) // error -object test4 with +object test4: - class C with + class C: val x = 0 - object Test with + object Test: val x = 1 - class D extends C with + class D extends C: def x(y: Int) = 3 val y: Int = this.x // OK val z: Int = x // OK end test4 val global = 0 -class C with +class C: val global = 1 -object D extends C with +object D extends C: println(global) // OK, since global is defined in package \ No newline at end of file diff --git a/tests/neg/bad-unapplies.scala b/tests/neg/bad-unapplies.scala index ab898d6f86c3..6bf70c3ae6d3 100644 --- a/tests/neg/bad-unapplies.scala +++ b/tests/neg/bad-unapplies.scala @@ -1,19 +1,19 @@ trait A trait B class C extends A, B -object A with +object A: def unapply(x: A): Option[String] = Some(x.toString) def unapply(x: B): Option[String] = Some(x.toString) object B -object D with +object D: def unapply(x: A, y: B): Option[String] = Some(x.toString) -object E with +object E: val unapply: Option[String] = Some("") -object F with +object F: def unapply(x: Int): Boolean = true diff --git a/tests/neg/case-semi.scala b/tests/neg/case-semi.scala index d05919805fa6..b7dfe0a7e524 100644 --- a/tests/neg/case-semi.scala +++ b/tests/neg/case-semi.scala @@ -1,4 +1,4 @@ -object Test with +object Test: type X = Int val x: X = 1 diff --git a/tests/neg/creator-ambiguous.scala b/tests/neg/creator-ambiguous.scala index feed4083ff56..dd476933db1e 100644 --- a/tests/neg/creator-ambiguous.scala +++ b/tests/neg/creator-ambiguous.scala @@ -2,11 +2,11 @@ // This used to succeed with old creator methods scheme // What happened was: the overloading resolution gave an ambiguous // overload, but then the falblback picked the constructor -object Test with +object Test: case class Record(elems: (String, Any)*) - object Record with + object Record: inline def apply[R <: Record](elems: (String, Any)*) : R = new Record(elems: _*).asInstanceOf[R] diff --git a/tests/neg/curried-dependent-ift.scala b/tests/neg/curried-dependent-ift.scala index 8aab2dd89ebe..359514505613 100644 --- a/tests/neg/curried-dependent-ift.scala +++ b/tests/neg/curried-dependent-ift.scala @@ -1,9 +1,9 @@ -trait Ctx1 with +trait Ctx1: type T val x: T val y: T -trait Ctx2 with +trait Ctx2: type T val x: T val y: T diff --git a/tests/neg/endmarkers.scala b/tests/neg/endmarkers.scala index 19880fbc7beb..5c7c1c686cd0 100644 --- a/tests/neg/endmarkers.scala +++ b/tests/neg/endmarkers.scala @@ -1,4 +1,4 @@ -object Test with +object Test: locally { var x = 0 @@ -43,11 +43,11 @@ object Test with x < 10 do () -class Test2 with +class Test2: self => def foo = 1 - object x with + object x: new Test2 { override def foo = 2 end new // error: misaligned end marker @@ -56,16 +56,16 @@ class Test2 with end Test2 // error: misaligned end marker end Test2 -class Test3 with +class Test3: self => def foo = 1 end Test3 // error: misaligned end marker import collection.mutable.HashMap -class Coder(words: List[String]) with +class Coder(words: List[String]): - class Foo with + class Foo: println() end Foo // error: misaligned end marker diff --git a/tests/neg/endmarkers1.scala b/tests/neg/endmarkers1.scala index 2205395b0036..b2b746c57371 100644 --- a/tests/neg/endmarkers1.scala +++ b/tests/neg/endmarkers1.scala @@ -4,7 +4,7 @@ def f7[T](x: Option[T]) = x match case None => end if // error: misaligned end marker -object Test4 with +object Test4: def f[T](x: Option[T]) = x match case Some(y) => case None => diff --git a/tests/neg/enum-values.scala b/tests/neg/enum-values.scala index 9bf531abae98..08069251af0e 100644 --- a/tests/neg/enum-values.scala +++ b/tests/neg/enum-values.scala @@ -1,26 +1,26 @@ package example -enum Tag[T] with +enum Tag[T]: case Int extends Tag[Int] case String extends Tag[String] case OfClass[T]()(using val tag: reflect.ClassTag[T]) extends Tag[T] -enum ListLike[+T] with +enum ListLike[+T]: case Cons[T](head: T, tail: ListLike[T]) extends ListLike[T] case EmptyListLike -object ListLike with +object ListLike: def valuef(s: String): ListLike[?] = ??? // this will usually trigger a "- did you mean ListLike.valuef" addendum -object Extensions with +object Extensions: extension (foo: Nothing) // this will usually trigger an attempted extension method addendum def values: Array[Tag[?]] = ??? -enum TypeCtorsK[F[_]] with +enum TypeCtorsK[F[_]]: case List extends TypeCtorsK[List] case Option extends TypeCtorsK[Option] case Const[T]() extends TypeCtorsK[[U] =>> T] -object UnimportedExtensions with +object UnimportedExtensions: extension (TypeCtorsKModule: TypeCtorsK.type) // this will usually trigger an import suggestions addendum def valueOf(name: String): TypeCtorsK[?] = ??? diff --git a/tests/neg/enums.scala b/tests/neg/enums.scala index c43fb829d9b9..6335def433c1 100644 --- a/tests/neg/enums.scala +++ b/tests/neg/enums.scala @@ -42,10 +42,10 @@ enum Option[+T] derives CanEqual { object DollarNew { - enum MyEnum with + enum MyEnum: case A - object MyEnum with + object MyEnum: def $new: MyEnum = new MyEnum with runtime.EnumValue { // error: anonymous class in method $new extends enum MyEnum, but extending enums is prohibited. override def $ordinal = 1 diff --git a/tests/neg/enumvalues.scala b/tests/neg/enumvalues.scala index 10aa4f3eb6d9..f9d847f5fb63 100644 --- a/tests/neg/enumvalues.scala +++ b/tests/neg/enumvalues.scala @@ -1,7 +1,7 @@ -enum Color with +enum Color: case Red, Green, Blue -enum Option[+T] with +enum Option[+T]: case None extends Option[Nothing] import scala.runtime.EnumValue diff --git a/tests/neg/eql.scala b/tests/neg/eql.scala index a68f73bd5a8a..58378800bbc5 100644 --- a/tests/neg/eql.scala +++ b/tests/neg/eql.scala @@ -1,6 +1,6 @@ -object lst with +object lst: opaque type Lst[+T] = Any - object Lst with + object Lst: given lstCanEqual[T, U]: CanEqual[Lst[T], Lst[U]] = CanEqual.derived val Empty: Lst[Nothing] = ??? end lst diff --git a/tests/neg/exports1.scala b/tests/neg/exports1.scala index 698ab25ac7f8..ecd89c694043 100644 --- a/tests/neg/exports1.scala +++ b/tests/neg/exports1.scala @@ -1,20 +1,20 @@ -object A with +object A: def f: String = "" -trait B with +trait B: def f: String = "abc" -trait B2 extends B with +trait B2 extends B: override def f: String = "abc" -object D extends B with +object D extends B: object b extends B export b._ // ok -object D1 extends B with +object D1 extends B: object b extends B export b.f // error -object D2 extends B with +object D2 extends B: object b2 extends B2 export b2.f // error diff --git a/tests/neg/exports2.scala b/tests/neg/exports2.scala index 6fa18ae52900..913248a2041a 100644 --- a/tests/neg/exports2.scala +++ b/tests/neg/exports2.scala @@ -1,9 +1,9 @@ -object A with +object A: def f: String = "" -trait B with +trait B: def f: String = "abc" -object C extends B with +object C extends B: export A._ // error diff --git a/tests/neg/extend-java-enum-nonstatic.scala b/tests/neg/extend-java-enum-nonstatic.scala index 0bd72cc7d7da..5f0b6d36f8a8 100644 --- a/tests/neg/extend-java-enum-nonstatic.scala +++ b/tests/neg/extend-java-enum-nonstatic.scala @@ -1,22 +1,22 @@ import java.{lang => jl} -object TestSuite with +object TestSuite: def test(op: => Unit): Unit = op test { enum E extends jl.Enum[E] { case A } // error: enum extending java.lang.Enum must be declared in a static scope } -class Container with +class Container: enum E extends jl.Enum[E] { case A } // error: enum extending java.lang.Enum must be declared in a static scope -object Wrap with +object Wrap: def force = enum E extends jl.Enum[E] { case A } // error: enum extending java.lang.Enum must be declared in a static scope -trait Universe with +trait Universe: enum E extends jl.Enum[E] { case A } // error: enum extending java.lang.Enum must be declared in a static scope enum E extends jl.Enum[E] { case A } // ok, a declaration at package level is static. -object Static with +object Static: enum E extends jl.Enum[E] { case A } // ok, a declaration within a static object is static. diff --git a/tests/neg/extension-colon.check b/tests/neg/extension-colon.check new file mode 100644 index 000000000000..1760afe1ff50 --- /dev/null +++ b/tests/neg/extension-colon.check @@ -0,0 +1,4 @@ +-- Error: tests/neg/extension-colon.scala:1:18 ------------------------------------------------------------------------- +1 |extension (x: Int): // error + | ^ + | no `:` expected here diff --git a/tests/neg/extension-colon.scala b/tests/neg/extension-colon.scala new file mode 100644 index 000000000000..61585d5488c2 --- /dev/null +++ b/tests/neg/extension-colon.scala @@ -0,0 +1,2 @@ +extension (x: Int): // error + def foo = x diff --git a/tests/neg/extension-with.check b/tests/neg/extension-with.check deleted file mode 100644 index b331d7e5b783..000000000000 --- a/tests/neg/extension-with.check +++ /dev/null @@ -1,6 +0,0 @@ --- Error: tests/neg/extension-with.scala:1:19 -------------------------------------------------------------------------- -1 |extension (x: Int) with // error - | ^^^^ - | No `with` expected here. - | - | An extension clause is simply followed by one or more method definitions. diff --git a/tests/neg/extension-with.scala b/tests/neg/extension-with.scala deleted file mode 100644 index 0e19cc70466b..000000000000 --- a/tests/neg/extension-with.scala +++ /dev/null @@ -1,2 +0,0 @@ -extension (x: Int) with // error - def foo = x diff --git a/tests/neg/gadt-approximation-interaction.scala b/tests/neg/gadt-approximation-interaction.scala index 39ed7c1ce60b..683d0668f4a2 100644 --- a/tests/neg/gadt-approximation-interaction.scala +++ b/tests/neg/gadt-approximation-interaction.scala @@ -1,5 +1,5 @@ object MemberHealing { - enum SUB[-A, +B] with + enum SUB[-A, +B]: case Refl[S]() extends SUB[S, S] def foo[T](t: T, ev: T SUB Int) = @@ -9,7 +9,7 @@ object MemberHealing { } object ImplicitLookup { - enum SUB[-A, +B] with + enum SUB[-A, +B]: case Refl[S]() extends SUB[S, S] class Tag[T] @@ -23,7 +23,7 @@ object ImplicitLookup { } object GivenLookup { - enum SUB[-A, +B] with + enum SUB[-A, +B]: case Refl[S]() extends SUB[S, S] class Tag[T] @@ -37,10 +37,10 @@ object GivenLookup { } object ImplicitConversion { - enum SUB[-A, +B] with + enum SUB[-A, +B]: case Refl[S]() extends SUB[S, S] - class Pow(self: Int) with + class Pow(self: Int): def **(other: Int): Int = math.pow(self, other).toInt implicit def pow(i: Int): Pow = Pow(i) @@ -57,10 +57,10 @@ object ImplicitConversion { } object GivenConversion { - enum SUB[-A, +B] with + enum SUB[-A, +B]: case Refl[S]() extends SUB[S, S] - class Pow(self: Int) with + class Pow(self: Int): def **(other: Int): Int = math.pow(self, other).toInt given Conversion[Int, Pow] = (i: Int) => Pow(i) @@ -77,7 +77,7 @@ object GivenConversion { } object ExtensionMethod { - enum SUB[-A, +B] with + enum SUB[-A, +B]: case Refl[S]() extends SUB[S, S] extension (x: Int) @@ -90,10 +90,10 @@ object ExtensionMethod { } object HKFun { - enum SUB[-A, +B] with + enum SUB[-A, +B]: case Refl[S]() extends SUB[S, S] - enum HKSUB[-F[_], +G[_]] with + enum HKSUB[-F[_], +G[_]]: case Refl[H[_]]() extends HKSUB[H, H] def foo[F[_], T](ft: F[T], hkev: F HKSUB Option, ev: T SUB Int) = @@ -107,7 +107,7 @@ object HKFun { } } - enum COVHKSUB[-F[+_], +G[+_]] with + enum COVHKSUB[-F[+_], +G[+_]]: case Refl[H[_]]() extends COVHKSUB[H, H] def bar[F[+_], T](ft: F[T], hkev: F COVHKSUB Option, ev: T SUB Int) = @@ -123,7 +123,7 @@ object HKFun { } object NestedConstrained { - enum SUB[-A, +B] with + enum SUB[-A, +B]: case Refl[S]() extends SUB[S, S] def foo[A, B](a: A, ev1: A SUB Option[B], ev2: B SUB Int) = diff --git a/tests/neg/given-eta.scala b/tests/neg/given-eta.scala index 6b0ae63947e4..db9ab3744963 100644 --- a/tests/neg/given-eta.scala +++ b/tests/neg/given-eta.scala @@ -1,5 +1,5 @@ -trait D with +trait D: type T def trans(other: T): T diff --git a/tests/neg/i10546.scala b/tests/neg/i10546.scala index cfe31a7e9e38..33407872f77e 100644 --- a/tests/neg/i10546.scala +++ b/tests/neg/i10546.scala @@ -1,4 +1,4 @@ -object test with +object test: def times(num : Int)(block : => Unit) : Unit = () times(10): println("ah") // error: end of statement expected but '(' found // error diff --git a/tests/neg/i10817.scala b/tests/neg/i10817.scala index 6a3e01fca9ea..c9388274fc25 100644 --- a/tests/neg/i10817.scala +++ b/tests/neg/i10817.scala @@ -1,6 +1,6 @@ import annotation.static -class T with +class T: @static val foo = 10 // error val x = (new T).foo \ No newline at end of file diff --git a/tests/neg/i10857.scala b/tests/neg/i10857.scala index 1ab4d9d5091e..b9128933484f 100644 --- a/tests/neg/i10857.scala +++ b/tests/neg/i10857.scala @@ -1,25 +1,25 @@ -object Module with +object Module: class Bar class Baz class Qux - object Givens with + object Givens: given GivenBar: Bar = new Bar() def GivenBar(ignored: Int): Bar = new Bar() class GivenBar - object Members with + object Members: given Member: Baz = new Baz() private def Member(ignored1: String)(ignored2: Int): Bar = new Bar() def Member(ignored: Int): Baz = new Baz() class Member - object Combined with + object Combined: given GivenQux: Qux = new Qux() def GivenQux(ignored: Int): Qux = new Qux() - enum Color with + enum Color: case Red, Green, Blue export Color._ // will only export synthetic defs with same name as standard definition diff --git a/tests/neg/i10870.scala b/tests/neg/i10870.scala index 9d840ad1f4a0..55669d580dc5 100644 --- a/tests/neg/i10870.scala +++ b/tests/neg/i10870.scala @@ -1,7 +1,7 @@ final case class A() final case class B(a:A) -object Test with +object Test: extension(a:A) def x = 5 diff --git a/tests/neg/i10901.scala b/tests/neg/i10901.scala index c163a8e427ea..9552047c402f 100644 --- a/tests/neg/i10901.scala +++ b/tests/neg/i10901.scala @@ -52,10 +52,10 @@ object BugExp4Point2D { class C -object Container with +object Container: given C with {} -object Test with +object Test: extension (x: String)(using C) def foo: String = x diff --git a/tests/neg/i11066.scala b/tests/neg/i11066.scala index c61694f31cd0..4b8e16e85e9d 100644 --- a/tests/neg/i11066.scala +++ b/tests/neg/i11066.scala @@ -1,12 +1,12 @@ class PreferredPrompt(val preference: String) -object Greeter with +object Greeter: def greet(name: String)(using prompt: PreferredPrompt) = println(s"Welcome, $name. The system is ready.") println(prompt.preference) -object JillsPrefs with +object JillsPrefs: given jillsPrompt: PreferredPrompt = PreferredPrompt("Your wish> ") -object JoesPrefs with +object JoesPrefs: given joesPrompt: PreferredPrompt = PreferredPrompt("relax> ") diff --git a/tests/neg/i11081.scala b/tests/neg/i11081.scala index 4385f7039984..7c1e6ce6dec6 100644 --- a/tests/neg/i11081.scala +++ b/tests/neg/i11081.scala @@ -1,6 +1,6 @@ -enum Outer with +enum Outer: case Foo(u: Unavailable) // error case Bar(u: DefinitelyNotAvailable) // error -object Outer with +object Outer: class Unavailable(i: Int) case class DefinitelyNotAvailable() diff --git a/tests/neg/i1501.scala b/tests/neg/i1501.scala index dbc08a7ba442..68556640383a 100644 --- a/tests/neg/i1501.scala +++ b/tests/neg/i1501.scala @@ -24,5 +24,5 @@ object Test2 { trait TSubA extends SubA(2) // error: trait TSubA may not call constructor of class SubA - class Foo extends TA with TSubA // error: missing argument for parameter x of constructor SubA with + class Foo extends TA with TSubA // error: missing argument for parameter x of constructor SubA: } diff --git a/tests/neg/i3253.scala b/tests/neg/i3253.scala index 20965742046f..04a79bb73ea0 100644 --- a/tests/neg/i3253.scala +++ b/tests/neg/i3253.scala @@ -1,5 +1,5 @@ import Test.test -class A with +class A: def test = " " * 10 // error object Test extends A diff --git a/tests/neg/i6183.scala b/tests/neg/i6183.scala index e9de3fde8ee8..30eae3abdbe3 100644 --- a/tests/neg/i6183.scala +++ b/tests/neg/i6183.scala @@ -1,4 +1,4 @@ -object Test with +object Test: extension [A](a: A) def render: String = "Hi" extension [B](b: B) def render(using DummyImplicit): Char = 'x' diff --git a/tests/neg/i6205.scala b/tests/neg/i6205.scala index fd1d0202f552..32537e5b2fbb 100644 --- a/tests/neg/i6205.scala +++ b/tests/neg/i6205.scala @@ -1,6 +1,6 @@ class Contra[-T >: Null] -object Test with +object Test: def foo = // error class A new Contra[A] diff --git a/tests/neg/i6779.scala b/tests/neg/i6779.scala index 805ae9c54eb2..c83a2368940e 100644 --- a/tests/neg/i6779.scala +++ b/tests/neg/i6779.scala @@ -3,7 +3,7 @@ type G[T] type Stuff given Stuff = ??? -object Test with +object Test: extension [T](x: T) def f(using Stuff): F[T] = ??? diff --git a/tests/neg/i7359-g.scala b/tests/neg/i7359-g.scala index e22b39e2b370..ad7082dd21e3 100644 --- a/tests/neg/i7359-g.scala +++ b/tests/neg/i7359-g.scala @@ -1,4 +1,4 @@ -trait SAMTrait with +trait SAMTrait: def first(): String def equals(obj: Int): Boolean diff --git a/tests/neg/i7359.scala b/tests/neg/i7359.scala index e229af5e85ab..c65a33a66a18 100644 --- a/tests/neg/i7359.scala +++ b/tests/neg/i7359.scala @@ -1,3 +1,3 @@ -trait SAMTrait with +trait SAMTrait: def first(): String def notify(): Unit // error diff --git a/tests/neg/i7526.scala b/tests/neg/i7526.scala index 57119abdf054..ed37df14aa73 100644 --- a/tests/neg/i7526.scala +++ b/tests/neg/i7526.scala @@ -1,9 +1,9 @@ type Tr[-I, +O, +A] = I => (O, A) -trait NetApi with +trait NetApi: type Comp -trait NetDB extends NetApi with +trait NetDB extends NetApi: class Comp trait NetHelper extends NetApi diff --git a/tests/neg/i7709.scala b/tests/neg/i7709.scala index 2e7236c9fb8d..80bc4d8d518f 100644 --- a/tests/neg/i7709.scala +++ b/tests/neg/i7709.scala @@ -1,31 +1,31 @@ -object X with +object X: protected class Y -object A with +object A: class B extends X.Y // error class B2 extends X.Y: // error def this(n: Int) = this() class B3(x: Any) class B4 extends B3(new X.Y) // error - class B5(x: String) with + class B5(x: String): def this(n: Int) = this(new X.Y().toString) // error -trait T with +trait T: class B extends X.Y // error -class XX with +class XX: protected class Y -class C with +class C: def xx = new XX def y = new xx.Y // error -class D with +class D: def this(n: Int) = { this() def xx = new XX def y = new xx.Y // error } -class YY extends XX with +class YY extends XX: def y = new Y package p: - object X with + object X: protected class Y class Q extends X.Y // error diff --git a/tests/neg/i7980.scala b/tests/neg/i7980.scala index 6d950830e58a..b2f769056dcb 100644 --- a/tests/neg/i7980.scala +++ b/tests/neg/i7980.scala @@ -1,6 +1,6 @@ trait Evidence[X] -trait Trait[X : Evidence] with +trait Trait[X : Evidence]: def method(x : X) : X given ev: Evidence[Int] = new Evidence[Int]{} diff --git a/tests/neg/i8050.scala b/tests/neg/i8050.scala index 94520c3d3de7..029e8d8195d5 100644 --- a/tests/neg/i8050.scala +++ b/tests/neg/i8050.scala @@ -1,4 +1,4 @@ -object stuff with +object stuff: def exec(dir: Int) = ??? extension (a: Int) diff --git a/tests/neg/i8069.scala b/tests/neg/i8069.scala index fc94d7c057a1..50f8b7a3480e 100644 --- a/tests/neg/i8069.scala +++ b/tests/neg/i8069.scala @@ -1,7 +1,7 @@ -trait A with +trait A: type B -enum Test with +enum Test: case Test(a: A, b: a.B) // error: Implementation restriction: case classes cannot have dependencies between parameters case class Test2(a: A, b: a.B) // error: Implementation restriction: case classes cannot have dependencies between parameters diff --git a/tests/neg/i8333.scala b/tests/neg/i8333.scala index e5c19bd37228..12a35ac2d636 100644 --- a/tests/neg/i8333.scala +++ b/tests/neg/i8333.scala @@ -1,12 +1,12 @@ -class A with +class A: type T = Int // can also be class T -class B(x: A, y: A) with +class B(x: A, y: A): export x._ export y._ // error: duplicate -class C(x: A) with +class C(x: A): type T = String export x._ // error: duplicate -class D(x: A) with +class D(x: A): export x._ // error: duplicate type T = String diff --git a/tests/neg/i8407.scala b/tests/neg/i8407.scala index 941412d462b0..34d7fa20914c 100644 --- a/tests/neg/i8407.scala +++ b/tests/neg/i8407.scala @@ -1,4 +1,4 @@ -object Test with +object Test: val xs = List(1, 2, 3, 4, 5) xs match { case List(1, 2, xs1 @ xs2: _*) => println(xs2) // error // error diff --git a/tests/neg/i8623.scala b/tests/neg/i8623.scala index f07a911a27c1..f402a6ceeedd 100644 --- a/tests/neg/i8623.scala +++ b/tests/neg/i8623.scala @@ -1,6 +1,6 @@ -trait QC with - object tasty with +trait QC: + object tasty: type Tree extension (tree: Tree) def pos: Tree = ??? diff --git a/tests/neg/i8731.scala b/tests/neg/i8731.scala index 6f20519a5be7..97ae8308b20b 100644 --- a/tests/neg/i8731.scala +++ b/tests/neg/i8731.scala @@ -1,4 +1,4 @@ -object test with +object test: 3 match case 3 => ??? diff --git a/tests/neg/i9014.scala b/tests/neg/i9014.scala index 287d29d392bf..2a82d54be9d9 100644 --- a/tests/neg/i9014.scala +++ b/tests/neg/i9014.scala @@ -1,4 +1,4 @@ trait Bar -object Bar with +object Bar: inline given Bar = compiletime.error("Failed to expand!") val tests = summon[Bar] // error diff --git a/tests/neg/i9051.scala b/tests/neg/i9051.scala index cb2908ce83de..360f3b20eec7 100644 --- a/tests/neg/i9051.scala +++ b/tests/neg/i9051.scala @@ -1,11 +1,11 @@ package zio: class ZRef - object ZRef with + object ZRef: - private[zio] implicit class ZRefSyntax(private val self: ZRef) with + private[zio] implicit class ZRefSyntax(private val self: ZRef): def unsafeUpdate: Boolean = true -object Main with +object Main: val ref = new zio.ZRef println(ref.unsafeUpdate) // error diff --git a/tests/neg/i9437.scala b/tests/neg/i9437.scala index 389945ba3985..13cb2e74dc7a 100644 --- a/tests/neg/i9437.scala +++ b/tests/neg/i9437.scala @@ -1,7 +1,7 @@ class Bag extends reflect.Selectable @main def Test = - val x = new Bag with + val x = new Bag: val f1 = 23 println(x.f1()) // error \ No newline at end of file diff --git a/tests/neg/i9562.scala b/tests/neg/i9562.scala index d73df61895df..23d1bebdbba9 100644 --- a/tests/neg/i9562.scala +++ b/tests/neg/i9562.scala @@ -1,7 +1,7 @@ -class Foo with +class Foo: def foo = 23 -object Unrelated with +object Unrelated: extension (f: Foo) def g = f.foo // OK diff --git a/tests/neg/i9790.scala b/tests/neg/i9790.scala index d247222ee0bc..3417c4b2c7b0 100644 --- a/tests/neg/i9790.scala +++ b/tests/neg/i9790.scala @@ -1,4 +1,4 @@ -object A with +object A: def fn: Unit = if true then println(1) diff --git a/tests/neg/i9928.scala b/tests/neg/i9928.scala index 44e4a35bb982..a1034b1f20e9 100644 --- a/tests/neg/i9928.scala +++ b/tests/neg/i9928.scala @@ -1,14 +1,14 @@ -trait Magic[F] with +trait Magic[F]: extension (x: Int) def read: F -object Magic with +object Magic: given Magic[String] with extension(x: Int) def read: String = println("In string") s"$x" opaque type Foo = String -object Foo with +object Foo: import Magic.given def apply(s: String): Foo = s diff --git a/tests/neg/import-given.scala b/tests/neg/import-given.scala index f1ad6aeb5880..ddc3da2fa5cb 100644 --- a/tests/neg/import-given.scala +++ b/tests/neg/import-given.scala @@ -25,6 +25,6 @@ object E { foo // ok foo(using tc) // ok } -object F with +object F: import A.{given ?} // error: unbound wildcard type diff --git a/tests/neg/inline-abstract.scala b/tests/neg/inline-abstract.scala index 95f67ae4ba5d..2f4596f38ea6 100644 --- a/tests/neg/inline-abstract.scala +++ b/tests/neg/inline-abstract.scala @@ -1,7 +1,7 @@ -class A with +class A: inline def f(): Int -class B extends A with +class B extends A: inline def f() = 1 def Test = diff --git a/tests/neg/missing-implicit1.scala b/tests/neg/missing-implicit1.scala index 30ba99904186..66c70f446d37 100644 --- a/tests/neg/missing-implicit1.scala +++ b/tests/neg/missing-implicit1.scala @@ -1,4 +1,4 @@ -object testObjectInstance with +object testObjectInstance: trait Zip[F[_]] trait Traverse[F[_]] { extension [A, B, G[_] : Zip](fa: F[A]) def traverse(f: A => G[B]): G[F[B]] diff --git a/tests/neg/missing-implicit2.scala b/tests/neg/missing-implicit2.scala index a673797e8738..53e30eeb9ee1 100644 --- a/tests/neg/missing-implicit2.scala +++ b/tests/neg/missing-implicit2.scala @@ -1,6 +1,6 @@ trait X trait Y -object test with +object test: def f(using x: X) = ??? object instances { given y: Y = ??? diff --git a/tests/neg/missing-implicit5.scala b/tests/neg/missing-implicit5.scala index a9132b0407d8..c294412da53b 100644 --- a/tests/neg/missing-implicit5.scala +++ b/tests/neg/missing-implicit5.scala @@ -1,4 +1,4 @@ -object testObjectInstance with +object testObjectInstance: trait Zip[F[_]] trait Traverse[F[_]] { extension [A, B, G[_] : Zip](fa: F[A]) def traverse(f: A => G[B]): G[F[B]] diff --git a/tests/neg/name-hints.scala b/tests/neg/name-hints.scala index aca20e067e0f..cb4cb8884087 100644 --- a/tests/neg/name-hints.scala +++ b/tests/neg/name-hints.scala @@ -1,8 +1,8 @@ -object O with +object O: val abcde: Int = 0 val xy: Int = 1 -object Test with +object Test: val x1 = Int.maxvalue // error val x2 = Int.MxValue // error val x3 = Int.MaxxValue // error diff --git a/tests/neg/namedTypeParams.scala b/tests/neg/namedTypeParams.scala index bc78ac09a208..8ed7c92241ea 100644 --- a/tests/neg/namedTypeParams.scala +++ b/tests/neg/namedTypeParams.scala @@ -1,7 +1,7 @@ class C[T] class D[type T] // error: identifier expected, but `type` found -object Test0 with +object Test0: def f[X, Y](x: X, y: Y): Int = ??? f[X = Int, Y = Int](1, 2) // error: experimental // error: experimental diff --git a/tests/neg/null-anyval.scala b/tests/neg/null-anyval.scala index df54c48bfd8a..82b4b9ad9433 100644 --- a/tests/neg/null-anyval.scala +++ b/tests/neg/null-anyval.scala @@ -1,4 +1,4 @@ -object Test with +object Test: val x: Int = 0 val y: Int | Null = x // during erasure, x is boxed here, and Int | Null becomes Object val z0: Int = identity(y) // error @@ -8,5 +8,5 @@ object Test with class StrWrapper(x: String) extends AnyVal val z3: StrWrapper = null // error val z4: O.T = null // error -object O with +object O: opaque type T = String diff --git a/tests/neg/override-erasure-clash.scala b/tests/neg/override-erasure-clash.scala index 6706004964c5..688eb816afcc 100644 --- a/tests/neg/override-erasure-clash.scala +++ b/tests/neg/override-erasure-clash.scala @@ -1,5 +1,5 @@ import annotation.targetName -class A with +class A: def f(): Int = 1 class B extends A: // error @targetName("f") def g(): Int = 2 diff --git a/tests/neg/override-inner-class.scala b/tests/neg/override-inner-class.scala index 5ff65519f5bd..4c4daaccb88a 100644 --- a/tests/neg/override-inner-class.scala +++ b/tests/neg/override-inner-class.scala @@ -1,5 +1,5 @@ -class C with +class C: type T >: String <: Any -class D extends C with +class D extends C: class T // error diff --git a/tests/neg/source-import.scala b/tests/neg/source-import.scala index 5479f823d91a..5cb7f532ea5c 100644 --- a/tests/neg/source-import.scala +++ b/tests/neg/source-import.scala @@ -1,6 +1,6 @@ import language.`3.0` import language.`3.0` // error -class C with +class C: import language.`3.0-migration` // error diff --git a/tests/neg/spaces-vs-tabs.scala b/tests/neg/spaces-vs-tabs.scala index c4e8bee9ada8..ff8d1a1c328e 100644 --- a/tests/neg/spaces-vs-tabs.scala +++ b/tests/neg/spaces-vs-tabs.scala @@ -1,4 +1,4 @@ -object Test with +object Test: if true then println(1) // ok @@ -7,7 +7,7 @@ object Test with println(4) // error else () // error - object Test2 with + object Test2: if true then 1 diff --git a/tests/neg/targetName-override-2.scala b/tests/neg/targetName-override-2.scala index 05b2071d3481..531efbfd931f 100644 --- a/tests/neg/targetName-override-2.scala +++ b/tests/neg/targetName-override-2.scala @@ -1,6 +1,6 @@ import annotation.targetName -class Alpha[T] with +class Alpha[T]: def foo() = 1 diff --git a/tests/neg/transparent-inline.scala b/tests/neg/transparent-inline.scala index be6b5ad65bab..a5158d9b8a27 100644 --- a/tests/neg/transparent-inline.scala +++ b/tests/neg/transparent-inline.scala @@ -1,6 +1,6 @@ transparent def bar: Any = 2 // error: transparent can be used only with inline -object test1 with +object test1: def x: Int = baz(true) // error: type mismatch inline def baz(x: Boolean): Any = @@ -9,7 +9,7 @@ object test1 with if x then 1 else "" def y: Int = bam(true) // error: type mismatch -object test2 with +object test2: def x: 1 = baz(true) // OK transparent inline def baz(x: Boolean) = @@ -18,7 +18,7 @@ object test2 with if x then 1 else "" def y: 1 = bam(true) // OK -object test3 with +object test3: def x: Int = baz(true) // error: type mismatch inline def baz(x: Boolean) = @@ -27,7 +27,7 @@ object test3 with if x then 1 else "" def y: Int = bam(true) // error: type mismatch -object test4 with +object test4: def x: 1 = baz(true) // OK transparent inline def baz(x: Boolean): Any = diff --git a/tests/neg/with-template.check b/tests/neg/with-template.check deleted file mode 100644 index fd33b39c16f6..000000000000 --- a/tests/neg/with-template.check +++ /dev/null @@ -1,22 +0,0 @@ --- Error: tests/neg/with-template.scala:6:5 ---------------------------------------------------------------------------- -6 | B with // error // error this one allows an informative hint - | ^^^^ - | end of statement expected but 'with' found - | - | Maybe you meant to write a mixin in an extends clause? - | Note that this requires the `with` to come first now. - | I.e. - | - | with B --- [E006] Not Found Error: tests/neg/with-template.scala:6:2 ----------------------------------------------------------- -6 | B with // error // error this one allows an informative hint - | ^ - | Not found: B - -longer explanation available when compiling with `-explain` --- [E006] Not Found Error: tests/neg/with-template.scala:10:2 ---------------------------------------------------------- -10 | B { // error this one is harder since it is syntactically correct - | ^ - | Not found: B - -longer explanation available when compiling with `-explain` diff --git a/tests/neg/with-template.scala b/tests/neg/with-template.scala deleted file mode 100644 index 881c78781c85..000000000000 --- a/tests/neg/with-template.scala +++ /dev/null @@ -1,20 +0,0 @@ -class A -trait B -trait C - -object Test extends A with - B with // error // error this one allows an informative hint - C - -object Test2 extends A with - B { // error this one is harder since it is syntactically correct - println("foo") - } - -def foo: A with - B with - C = ??? - - - - diff --git a/tests/new/test.scala b/tests/new/test.scala index 924334fca8e1..ac8f67d1530f 100644 --- a/tests/new/test.scala +++ b/tests/new/test.scala @@ -1,2 +1,3 @@ -object Test with - val x = 1 +object Test: + + def test = ??? diff --git a/tests/patmat/i10085.scala b/tests/patmat/i10085.scala index ac8d2b448eaf..314f4253cde8 100644 --- a/tests/patmat/i10085.scala +++ b/tests/patmat/i10085.scala @@ -1,10 +1,10 @@ -enum Bool with +enum Bool: case True case False import Bool._ -enum SBool[B <: Bool] with +enum SBool[B <: Bool]: case STrue extends SBool[True.type] case SFalse extends SBool[False.type] diff --git a/tests/patmat/i8922.scala b/tests/patmat/i8922.scala index 8fd616dbae58..946b1834998f 100644 --- a/tests/patmat/i8922.scala +++ b/tests/patmat/i8922.scala @@ -1,6 +1,6 @@ case class Token(tokenType: TokenType, lexeme: String, line: Int) -enum TokenType with +enum TokenType: // Single-character tokens. case MINUS, PLUS, SLASH, STAR, @@ -14,7 +14,7 @@ enum Expr { case Binary(left: Expr, operator: Token, right: Expr) } -object Interpreter with +object Interpreter: import Expr._ import TokenType._ diff --git a/tests/patmat/i8922c.scala b/tests/patmat/i8922c.scala index b6c07e43828c..63d968c80345 100644 --- a/tests/patmat/i8922c.scala +++ b/tests/patmat/i8922c.scala @@ -1,6 +1,6 @@ case class Token(tokenType: TokenType, lexeme: String, line: Int) -enum TokenType with +enum TokenType: // Single-character tokens. case MINUS, PLUS, SLASH, STAR, @@ -14,7 +14,7 @@ enum Expr { case Binary(left: Expr, operator: Token, right: Expr) } -object Interpreter with +object Interpreter: import Expr._ import TokenType._ diff --git a/tests/pending/pos/cps-async-failure.scala b/tests/pending/pos/cps-async-failure.scala index 6cb8d2482989..9f8da4c7f8b8 100644 --- a/tests/pending/pos/cps-async-failure.scala +++ b/tests/pending/pos/cps-async-failure.scala @@ -1,7 +1,7 @@ import scala.quoted._ -trait App[F[_],CT] with +trait App[F[_],CT]: this: Base[F,CT] => import quotes.reflect._ @@ -39,10 +39,10 @@ trait Base[F[_]:Type,CT:Type] // Both :Type context bounds are necessary for fa extends Cps with Root[F, CT] with App[F, CT]: implicit val qctx: Quotes -trait Root[F[_], CT] with +trait Root[F[_], CT]: this: Base[F, CT] => def runRoot(): CpsTree = ??? -trait Cps with +trait Cps: sealed abstract class CpsTree diff --git a/tests/pending/pos/inlinetuple.scala b/tests/pending/pos/inlinetuple.scala index 1fdb6abfd02f..ac457ebfa0d9 100644 --- a/tests/pending/pos/inlinetuple.scala +++ b/tests/pending/pos/inlinetuple.scala @@ -1,6 +1,6 @@ // TODO: Ensure that this inlines properly. So far only // x._1 inlines, but not x._2. -object Test with +object Test: def g(x: Int, y: Int) = x + y inline def f(inline x: (Int, Int)) = g(x._1, x._2) diff --git a/tests/pos-custom-args/erased/i10848b.scala b/tests/pos-custom-args/erased/i10848b.scala index bb808b6238f5..71292b1b859c 100644 --- a/tests/pos-custom-args/erased/i10848b.scala +++ b/tests/pos-custom-args/erased/i10848b.scala @@ -1,4 +1,4 @@ -class Foo with +class Foo: erased given Int = 1 def foo(using erased x: Int): Unit = () foo diff --git a/tests/pos-custom-args/erased/i7868.scala b/tests/pos-custom-args/erased/i7868.scala index 1676c31bab2f..2753cf444af4 100644 --- a/tests/pos-custom-args/erased/i7868.scala +++ b/tests/pos-custom-args/erased/i7868.scala @@ -12,14 +12,13 @@ object Coproduct { object At { - given atHead[Head, Tail]: At[Head +: Tail, Head, 0] { + given atHead[Head, Tail]: At[Head +: Tail, Head, 0] with { def cast: Head <:< Head +: Tail = summon[Head <:< Head +: Tail] } given atTail[Head, Tail, Value, NextIndex <: Int] (using atNext: At[Tail, Value, NextIndex]) - : At[Head +: Tail, Value, S[NextIndex]] - with + : At[Head +: Tail, Value, S[NextIndex]] with val cast: Value <:< Head +: Tail = atNext.cast given [A](using A): (() => A) = { () => summon[A]} diff --git a/tests/pos-custom-args/semanticdb/inline-unapply/Macro_1.scala b/tests/pos-custom-args/semanticdb/inline-unapply/Macro_1.scala index b15e2282961a..dc431c14ef14 100644 --- a/tests/pos-custom-args/semanticdb/inline-unapply/Macro_1.scala +++ b/tests/pos-custom-args/semanticdb/inline-unapply/Macro_1.scala @@ -1,6 +1,6 @@ import scala.quoted._ -object Succ with +object Succ: inline def unapply(n: Int): Option[Int] = ${ impl('n) } diff --git a/tests/pos-macros/i10151/Macro_1.scala b/tests/pos-macros/i10151/Macro_1.scala index b2ee78a860fa..f5170c83da12 100644 --- a/tests/pos-macros/i10151/Macro_1.scala +++ b/tests/pos-macros/i10151/Macro_1.scala @@ -2,20 +2,20 @@ package x import scala.quoted._ -trait CB[T] with +trait CB[T]: def map[S](f: T=>S): CB[S] = ??? def flatMap[S](f: T=>CB[S]): CB[S] = ??? -class MyArr[AK,AV] with +class MyArr[AK,AV]: def map1[BK,BV](f: ((AK,AV)) => (BK, BV)):MyArr[BK,BV] = ??? def map1Out[BK, BV](f: ((AK,AV)) => CB[(BK,BV)]): CB[MyArr[BK,BV]] = ??? def await[T](x:CB[T]):T = ??? -object CBM with +object CBM: def pure[T](t:T):CB[T] = ??? -object X with +object X: inline def process[T](inline f:T) = ${ processImpl[T]('f) diff --git a/tests/pos-macros/i10211/Macro_1.scala b/tests/pos-macros/i10211/Macro_1.scala index 72fa30e47cc7..ebf9b76ff77e 100644 --- a/tests/pos-macros/i10211/Macro_1.scala +++ b/tests/pos-macros/i10211/Macro_1.scala @@ -2,11 +2,11 @@ package x import scala.quoted._ -trait CB[T] with +trait CB[T]: def map[S](f: T=>S): CB[S] = ??? -class MyArr[A] with +class MyArr[A]: def map[B](f: A=>B):MyArr[B] = ??? def mapOut[B](f: A=> CB[B]): CB[MyArr[B]] = ??? def flatMap[B](f: A=>MyArr[B]):MyArr[B] = ??? @@ -15,7 +15,7 @@ class MyArr[A] with def withFilterOut(p: A=>CB[Boolean]): DelayedWithFilter[A] = ??? def map2[B](f: A=>B):MyArr[B] = ??? -class DelayedWithFilter[A] with +class DelayedWithFilter[A]: def map[B](f: A=>B):MyArr[B] = ??? def mapOut[B](f: A=> CB[B]): CB[MyArr[B]] = ??? def flatMap[B](f: A=>MyArr[B]):MyArr[B] = ??? @@ -25,11 +25,11 @@ class DelayedWithFilter[A] with def await[T](x:CB[T]):T = ??? -object CBM with +object CBM: def pure[T](t:T):CB[T] = ??? def map[T,S](a:CB[T])(f:T=>S):CB[S] = ??? -object X with +object X: inline def process[T](inline f:T) = ${ processImpl[T]('f) diff --git a/tests/pos-macros/i10771/MacroA_1.scala b/tests/pos-macros/i10771/MacroA_1.scala index 22b5be9e22c6..88da14fe31ac 100644 --- a/tests/pos-macros/i10771/MacroA_1.scala +++ b/tests/pos-macros/i10771/MacroA_1.scala @@ -2,7 +2,7 @@ import scala.quoted._ case class MyQuoted(val ast: String, runtimeQuotes: List[String]) -object MyQuoteMacro with +object MyQuoteMacro: inline def myquote: MyQuoted = ${ MyQuoteMacro.apply } def apply(using Quotes): Expr[MyQuoted] = '{ MyQuoted("p", ${Expr.ofList(List( '{ "foo" } ))}) } diff --git a/tests/pos-macros/i10771/MacroB_1.scala b/tests/pos-macros/i10771/MacroB_1.scala index 4eb1566461dd..e9bfe73fb1a2 100644 --- a/tests/pos-macros/i10771/MacroB_1.scala +++ b/tests/pos-macros/i10771/MacroB_1.scala @@ -1,6 +1,6 @@ import scala.quoted._ -object PullAst with +object PullAst: def applyImpl(quoted: Expr[MyQuoted])(using qctx: Quotes): Expr[String] = '{ $quoted.ast.toString } inline def apply(inline quoted: MyQuoted): String = diff --git a/tests/pos-macros/i10771/Test_2.scala b/tests/pos-macros/i10771/Test_2.scala index 30203c7cf9e2..7777454cfc36 100644 --- a/tests/pos-macros/i10771/Test_2.scala +++ b/tests/pos-macros/i10771/Test_2.scala @@ -1,3 +1,3 @@ -object Test with +object Test: def main(args: Array[String]): Unit = println( PullAst.apply( MyQuoteMacro.myquote ) ) diff --git a/tests/pos-macros/i10910/Macro_1.scala b/tests/pos-macros/i10910/Macro_1.scala index ccb32baa03d7..ae5643b1a9ea 100644 --- a/tests/pos-macros/i10910/Macro_1.scala +++ b/tests/pos-macros/i10910/Macro_1.scala @@ -2,15 +2,15 @@ package x import scala.quoted._ -trait CB[T] with +trait CB[T]: def map[S](f: T=>S): CB[S] = ??? def await[T](x:CB[T]):T = ??? -object CBM with +object CBM: def pure[T](t:T):CB[T] = ??? -object X with +object X: inline def process[T](inline f:T) = ${ processImpl[T]('f) diff --git a/tests/pos-macros/i8325/Macro_1.scala b/tests/pos-macros/i8325/Macro_1.scala index 037d995f23d7..b3f14e80157c 100644 --- a/tests/pos-macros/i8325/Macro_1.scala +++ b/tests/pos-macros/i8325/Macro_1.scala @@ -3,7 +3,7 @@ package a import scala.quoted._ -object A with +object A: inline def transform[A](inline expr: A): A = ${ transformImplExpr('expr) diff --git a/tests/pos-macros/i8325b/Macro_1.scala b/tests/pos-macros/i8325b/Macro_1.scala index 70808b82c8d7..aa4255f6f3a0 100644 --- a/tests/pos-macros/i8325b/Macro_1.scala +++ b/tests/pos-macros/i8325b/Macro_1.scala @@ -3,7 +3,7 @@ package a import scala.quoted._ -object A with +object A: inline def transform[A](inline expr: A): A = ${ transformImplExpr('expr) diff --git a/tests/pos-macros/i9812.scala b/tests/pos-macros/i9812.scala index 0764a1eeb827..e09db34fea2a 100644 --- a/tests/pos-macros/i9812.scala +++ b/tests/pos-macros/i9812.scala @@ -2,7 +2,7 @@ import quoted._ sealed abstract class SomeEnum -object SomeEnum with +object SomeEnum: final val Foo = new SomeEnum {} def quoteFoo: Quotes ?=> Expr[SomeEnum.Foo.type] = '{SomeEnum.Foo} diff --git a/tests/pos-macros/i9894/Macro_1.scala b/tests/pos-macros/i9894/Macro_1.scala index aa0e902ba300..7135cb6a7029 100644 --- a/tests/pos-macros/i9894/Macro_1.scala +++ b/tests/pos-macros/i9894/Macro_1.scala @@ -2,19 +2,19 @@ package x import scala.quoted._ -trait CB[T] with +trait CB[T]: def map[S](f: T=>S): CB[S] = ??? -class MyArr[A] with +class MyArr[A]: def map1[B](f: A=>B):MyArr[B] = ??? def map1Out[B](f: A=> CB[B]): CB[MyArr[B]] = ??? def await[T](x:CB[T]):T = ??? -object CBM with +object CBM: def pure[T](t:T):CB[T] = ??? -object X with +object X: inline def process[T](inline f:T) = ${ processImpl[T]('f) diff --git a/tests/pos-macros/nil-liftable.scala b/tests/pos-macros/nil-liftable.scala index 2771baff7078..490291bc48f7 100644 --- a/tests/pos-macros/nil-liftable.scala +++ b/tests/pos-macros/nil-liftable.scala @@ -1,6 +1,6 @@ import scala.quoted._ -class Test with +class Test: given NilToExpr: ToExpr[Nil.type] with { def apply(xs: Nil.type)(using Quotes): Expr[Nil.type] = '{ Nil } diff --git a/tests/pos-macros/quote-aliases.scala b/tests/pos-macros/quote-aliases.scala index 50b1b1b4566f..e6c0e50593fb 100644 --- a/tests/pos-macros/quote-aliases.scala +++ b/tests/pos-macros/quote-aliases.scala @@ -1,6 +1,6 @@ import scala.quoted._ -object Test with +object Test: def f1(using Quotes)(t: quotes.reflect.Tree): Unit = () diff --git a/tests/pos-special/fatal-warnings/i10259.scala b/tests/pos-special/fatal-warnings/i10259.scala index a089814cce80..5b4c628cd126 100644 --- a/tests/pos-special/fatal-warnings/i10259.scala +++ b/tests/pos-special/fatal-warnings/i10259.scala @@ -1,4 +1,4 @@ -trait S[T] extends (T => T) with +trait S[T] extends (T => T): def apply(x: T) = ??? extension (x: T) def show: String diff --git a/tests/pos-special/fatal-warnings/i9260.scala b/tests/pos-special/fatal-warnings/i9260.scala index a930a0b803a0..df548f393eea 100644 --- a/tests/pos-special/fatal-warnings/i9260.scala +++ b/tests/pos-special/fatal-warnings/i9260.scala @@ -1,14 +1,14 @@ package asts -enum Ast[-T >: Null] with +enum Ast[-T >: Null]: case DefDef() -trait AstImpl[T >: Null] with +trait AstImpl[T >: Null]: type Ast = asts.Ast[T] type DefDef = Ast.DefDef[T] end AstImpl -object untpd extends AstImpl[Null] with +object untpd extends AstImpl[Null]: def DefDef(ast: Ast): DefDef = ast match case ast: DefDef => ast diff --git a/tests/pos-special/fatal-warnings/patmat-exhaustive.scala b/tests/pos-special/fatal-warnings/patmat-exhaustive.scala index 796ada8a13a8..c5c95c455b8c 100644 --- a/tests/pos-special/fatal-warnings/patmat-exhaustive.scala +++ b/tests/pos-special/fatal-warnings/patmat-exhaustive.scala @@ -1,5 +1,5 @@ def foo: Unit = - object O with + object O: sealed abstract class A class B extends O.A class C extends O.A diff --git a/tests/pos-special/fatal-warnings/type-test-matchable.scala b/tests/pos-special/fatal-warnings/type-test-matchable.scala index 8e1acaa6dc44..5becee6f2e9f 100644 --- a/tests/pos-special/fatal-warnings/type-test-matchable.scala +++ b/tests/pos-special/fatal-warnings/type-test-matchable.scala @@ -1,13 +1,13 @@ import scala.language.`3.1-migration` import scala.reflect.TypeTest -trait Foo with +trait Foo: type X type Y <: X def x: X given TypeTest[X, Y] = ??? -object Test with +object Test: def test(foo: Foo): Unit = foo.x match case x: foo.Y => diff --git a/tests/pos-special/i7296.scala b/tests/pos-special/i7296.scala index 6811c80d7e77..3b582ad284b8 100644 --- a/tests/pos-special/i7296.scala +++ b/tests/pos-special/i7296.scala @@ -1,2 +1,2 @@ -class Foo with +class Foo: private var blah: Double = 0L \ No newline at end of file diff --git a/tests/pos-special/indent-colons.scala b/tests/pos-special/indent-colons.scala index e5b712ef2e77..44fe09b39cd4 100644 --- a/tests/pos-special/indent-colons.scala +++ b/tests/pos-special/indent-colons.scala @@ -1,4 +1,4 @@ -object Test with +object Test: locally: var x = 0 @@ -56,26 +56,26 @@ object Test with x < 10 do () -class Test2 with +class Test2: self => def foo = 1 val x = - new Test2 with + new Test2: override def foo = 2 end new end x end Test2 -class Test3 with +class Test3: self => def foo = 1 import collection.mutable.HashMap -class Coder(words: List[String]) with +class Coder(words: List[String]): - class Foo with + class Foo: println() end Foo @@ -114,5 +114,5 @@ class Coder(words: List[String]) with case (digit, str) => str map (ltr => ltr -> digit) end Coder -object Test22 with +object Test22: def foo: Int = 22 \ No newline at end of file diff --git a/tests/pos-special/notNull.scala b/tests/pos-special/notNull.scala index bcc0154b0a80..11a506d8184d 100644 --- a/tests/pos-special/notNull.scala +++ b/tests/pos-special/notNull.scala @@ -1,4 +1,4 @@ -object Test with +object Test: def notNull[A](x: A | Null): x.type & A = assert(x != null) x.asInstanceOf // TODO: drop the .asInstanceOf when explicit nulls are implemented diff --git a/tests/pos-special/sourcepath/outer/nested/indent1.scala b/tests/pos-special/sourcepath/outer/nested/indent1.scala index 0b2d74832f28..cba9ddddece1 100644 --- a/tests/pos-special/sourcepath/outer/nested/indent1.scala +++ b/tests/pos-special/sourcepath/outer/nested/indent1.scala @@ -1,8 +1,8 @@ package outer package nested -object indent1 with - object inner with +object indent1: + object inner: def x: Int = 1 end inner val y: Int = 2 diff --git a/tests/pos/abstract-givens.scala b/tests/pos/abstract-givens.scala deleted file mode 100644 index 9e8b23b127bf..000000000000 --- a/tests/pos/abstract-givens.scala +++ /dev/null @@ -1,9 +0,0 @@ -class C { type T } -trait A with - given C with {} // concrete - given c0: C {} // concrete - given c1: C {} // concrete - given c2: (C {type T <: Int}) // abstract with refinement - -object B extends A with - override given c2: C with { type T = Int } diff --git a/tests/pos/abstract-inline-val.scala b/tests/pos/abstract-inline-val.scala index ccf2ebd6ff60..6ea95eea5151 100644 --- a/tests/pos/abstract-inline-val.scala +++ b/tests/pos/abstract-inline-val.scala @@ -1,11 +1,11 @@ -trait C with +trait C: inline def x: Int inline val y: Int -class C1 extends C with +class C1 extends C: inline val x = 1 inline val y = 2 -class C2 extends C with +class C2 extends C: inline def x = 3 inline val y = 4 diff --git a/tests/pos/consume.scala b/tests/pos/consume.scala index 41965b522682..d17638bb84a0 100644 --- a/tests/pos/consume.scala +++ b/tests/pos/consume.scala @@ -1,4 +1,4 @@ -object Test1 with +object Test1: def consume(xs: List[Int], limit: Int): List[Int] = xs match case x :: xs1 if limit > 0 => consume(xs1, limit - x) case _ => xs @@ -16,18 +16,18 @@ object Test2 { } } -object math3 with - trait Ord[T] with +object math3: + trait Ord[T]: extension (x: T) def > (t: T): Boolean = ??? extension (x: T) def <= (t: T): Boolean = ??? - trait Numeric[T] extends Ord[T] with + trait Numeric[T] extends Ord[T]: extension (x: T) def + (y: T): T = ??? extension (x: T) def - (y: T): T = ??? extension (x: Int) def numeric: T = ??? end math3 -object Test3 with +object Test3: import math3.Numeric import collection.immutable.Seq diff --git a/tests/pos/end-nested.scala b/tests/pos/end-nested.scala index 96c25c2b1ea2..38e8cce6c8a9 100644 --- a/tests/pos/end-nested.scala +++ b/tests/pos/end-nested.scala @@ -3,7 +3,7 @@ def f[T](x: Option[T]) = x match case None => end f -object Test with +object Test: try List(1, 2, 3) match case x :: xs => println(x) case Nil => println("Nil") diff --git a/tests/pos/endmarkers.scala b/tests/pos/endmarkers.scala index 13c3b92912b7..5b85ce3763cd 100644 --- a/tests/pos/endmarkers.scala +++ b/tests/pos/endmarkers.scala @@ -1,5 +1,5 @@ -trait T with - object O with +trait T: + object O: def foo = 1 end foo @@ -13,7 +13,7 @@ end T package p1.p2: - abstract class C() with + abstract class C(): def this(x: Int) = this() @@ -42,9 +42,9 @@ package p1.p2: def f: String end C - object C with + object C: given C = - new C with + new C: def f = "!" end f end new diff --git a/tests/pos/enum-companion-first.scala b/tests/pos/enum-companion-first.scala index 014066fb43f4..d4c1eb370031 100644 --- a/tests/pos/enum-companion-first.scala +++ b/tests/pos/enum-companion-first.scala @@ -1,7 +1,7 @@ -object Planet with +object Planet: final val G = 6.67300E-11 -enum Planet(mass: Double, radius: Double) extends Enum[Planet] with +enum Planet(mass: Double, radius: Double) extends Enum[Planet]: def surfaceGravity = Planet.G * mass / (radius * radius) def surfaceWeight(otherMass: Double) = otherMass * surfaceGravity diff --git a/tests/pos/enum-variance.scala b/tests/pos/enum-variance.scala index ca13c44d7a3f..82fa5bdf91a0 100644 --- a/tests/pos/enum-variance.scala +++ b/tests/pos/enum-variance.scala @@ -1,14 +1,14 @@ class Animal class Dog extends Animal -enum Opt[+T] with +enum Opt[+T]: case Sm(t: T) case None val smDog: Opt.Sm[Dog] = new Opt.Sm(Dog()) val smAnimal: Opt.Sm[Animal] = smDog -enum Show[-T] with +enum Show[-T]: case Refl(op: T => String) def show(t: T): String = this match diff --git a/tests/pos/enum-widen.scala b/tests/pos/enum-widen.scala index 8fb4e8707da1..32bbcf9a3242 100644 --- a/tests/pos/enum-widen.scala +++ b/tests/pos/enum-widen.scala @@ -1,6 +1,6 @@ -object test with +object test: - enum Option[+T] with + enum Option[+T]: case Some[T](x: T) extends Option[T] case None @@ -13,7 +13,7 @@ object test with x = None xc = None - enum Nat with + enum Nat: case Z case S[N <: Z.type | S[_]](pred: N) import Nat._ diff --git a/tests/pos/extmethods.scala b/tests/pos/extmethods.scala index b8bc0f25dea6..368b4f439916 100644 --- a/tests/pos/extmethods.scala +++ b/tests/pos/extmethods.scala @@ -32,7 +32,7 @@ val y1: List[Int] = y val z = (1 :: Nil).concat(Nil) val z1: List[Int] = z -trait TT with +trait TT: type A val m: A def f[B <: A](x: B): A = if ??? then m else x @@ -40,7 +40,7 @@ trait TT with extension (x: TT) def foo[B <: x.A](y: B) = x.f(y) -object CC extends TT with +object CC extends TT: type A = Seq[Int] val m = Nil diff --git a/tests/pos/i10080.scala b/tests/pos/i10080.scala index 7fd859210910..81146e18ed82 100644 --- a/tests/pos/i10080.scala +++ b/tests/pos/i10080.scala @@ -1,2 +1,5 @@ +trait Foo: +end Foo + trait Bar end Bar diff --git a/tests/pos/i10082.scala b/tests/pos/i10082.scala index 5c989ecceffe..a1dc6160788e 100644 --- a/tests/pos/i10082.scala +++ b/tests/pos/i10082.scala @@ -1,4 +1,4 @@ -object Kotlin with +object Kotlin: def it[T](using t: T) = t def fun[T, U](fn: T ?=> U)(x: T): U = fn(using x) diff --git a/tests/pos/i10253.scala b/tests/pos/i10253.scala index aedd93ce45dd..15f872c59be0 100644 --- a/tests/pos/i10253.scala +++ b/tests/pos/i10253.scala @@ -1,9 +1,9 @@ -object test with +object test: def foo(qc: QC): Unit = object treeMap extends qc.reflect.TreeMap -trait QC with +trait QC: val reflect: Reflection - trait Reflection with - trait TreeMap with + trait Reflection: + trait TreeMap: def transformTree: Unit = ??? \ No newline at end of file diff --git a/tests/pos/i10295.scala b/tests/pos/i10295.scala index a100cca18cf8..8fc237e2e853 100644 --- a/tests/pos/i10295.scala +++ b/tests/pos/i10295.scala @@ -1,6 +1,6 @@ -trait M with +trait M: type X - object X with + object X: def foo(): X = ??? inline def m(using m: M): m.type = m diff --git a/tests/pos/i10311.scala b/tests/pos/i10311.scala index c89083446405..bfa0c15f3493 100644 --- a/tests/pos/i10311.scala +++ b/tests/pos/i10311.scala @@ -7,7 +7,7 @@ object Module { extension (self: MyInt) def y: Int = self.y } } -object test with +object test: import Module._ val a = new MyInt(42, 43) diff --git a/tests/pos/i10495.scala b/tests/pos/i10495.scala index 9eb2bb9b4976..931e5fe73f72 100644 --- a/tests/pos/i10495.scala +++ b/tests/pos/i10495.scala @@ -1,7 +1,7 @@ -class Foo with +class Foo: extension(x: String) def run: Unit = ??? -object Bar extends Foo with +object Bar extends Foo: def run(v: Int): Unit = ??? "ABC".run // Failed before: Reference to run is ambiguous... diff --git a/tests/pos/i10634/BasicSupport.scala b/tests/pos/i10634/BasicSupport.scala index 0e4f0fa31a82..cf4ae7190ce4 100644 --- a/tests/pos/i10634/BasicSupport.scala +++ b/tests/pos/i10634/BasicSupport.scala @@ -1,5 +1,5 @@ // BasicSupport.scala -trait BasicSupport with +trait BasicSupport: self: Parser => object SymOps extends SymOps[ctx.type](ctx) diff --git a/tests/pos/i10634/Context.scala b/tests/pos/i10634/Context.scala index 76ae72ae3f6b..0e22fd29d17d 100644 --- a/tests/pos/i10634/Context.scala +++ b/tests/pos/i10634/Context.scala @@ -1,8 +1,8 @@ // Context.scala -trait Context with +trait Context: type Symbol -trait SymOps[C <: Context](val c: C) with +trait SymOps[C <: Context](val c: C): extension (sym: c.Symbol) def getVisibility(): Int = 0 diff --git a/tests/pos/i10951.scala b/tests/pos/i10951.scala index fd71ca59c073..2520536a491c 100644 --- a/tests/pos/i10951.scala +++ b/tests/pos/i10951.scala @@ -1,6 +1,6 @@ import scala.language.dynamics -object Dyn extends Dynamic with +object Dyn extends Dynamic: def selectDynamic[T](name: String): Option[T] = None val a: Option[(Int, Int)] = Dyn.asdf[Tuple2[Int, Int]] diff --git a/tests/pos/i11015.scala b/tests/pos/i11015.scala index 9dfa44dc7fe6..30e919a646f6 100644 --- a/tests/pos/i11015.scala +++ b/tests/pos/i11015.scala @@ -1,5 +1,5 @@ import annotation.targetName -object Foo with +object Foo: def apply[A <: Int]: Int = 0 @targetName("applyS") def apply[B <: String]: String = "0" diff --git a/tests/pos/i11081.scala b/tests/pos/i11081.scala index d77f56505d7b..cd333d7e407d 100644 --- a/tests/pos/i11081.scala +++ b/tests/pos/i11081.scala @@ -1,6 +1,6 @@ -enum Outer with +enum Outer: case Foo -object Outer with +object Outer: trait Bar case class Baz(bar: Bar) case class Bam(bar: Bar = new Bar() {}) diff --git a/tests/pos/i11141.scala b/tests/pos/i11141.scala index 953df9d04c42..c0fc916ccb35 100644 --- a/tests/pos/i11141.scala +++ b/tests/pos/i11141.scala @@ -1,5 +1,5 @@ package p export X._ -object X with +object X: val A = 42 diff --git a/tests/pos/i11175.scala b/tests/pos/i11175.scala index 950b60bbce6f..bfefe84dde95 100644 --- a/tests/pos/i11175.scala +++ b/tests/pos/i11175.scala @@ -1,6 +1,6 @@ package x -trait Printer[T] with +trait Printer[T]: def print(t:T):String extension[T](t:T)(using Printer[T]) diff --git a/tests/pos/i4561.scala b/tests/pos/i4561.scala index a0791313633a..5a51cb668a37 100644 --- a/tests/pos/i4561.scala +++ b/tests/pos/i4561.scala @@ -1,6 +1,6 @@ -object abc with +object abc: trait Test0 - trait Test1[T] with + trait Test1[T]: def apply(f: T => T): Unit def apply(s: String): Unit diff --git a/tests/pos/i6375.scala b/tests/pos/i6375.scala index 4df662e3c1ec..aa682483b52d 100644 --- a/tests/pos/i6375.scala +++ b/tests/pos/i6375.scala @@ -28,7 +28,7 @@ } } */ -class Test with +class Test: given Int = 0 def f(): Int ?=> Boolean = true : (Int ?=> Boolean) diff --git a/tests/pos/i6734.scala b/tests/pos/i6734.scala index 904b36aa9e9b..fa7d9946ada4 100644 --- a/tests/pos/i6734.scala +++ b/tests/pos/i6734.scala @@ -1,4 +1,4 @@ -object Bug with +object Bug: extension [A, B, Z](ab: (A, B)) def pipe2(f: (A, B) => Z): Z = f(ab._1, ab._2) diff --git a/tests/pos/i6900.scala b/tests/pos/i6900.scala index 75999b25e7ec..55587a18b4ba 100644 --- a/tests/pos/i6900.scala +++ b/tests/pos/i6900.scala @@ -1,15 +1,15 @@ object Test1 { - trait Foo[A] with + trait Foo[A]: def foo[C]: C => A // Works with old-style conversion - implicit def i2f[A](a: A): Foo[A] = new Foo[A] with + implicit def i2f[A](a: A): Foo[A] = new Foo[A]: def foo[C]: C => A = _ => a // But not with newstyle /* given [A]: Conversion[A, Foo[A]] with - def apply(a: A) = new Foo[A] with + def apply(a: A) = new Foo[A]: def foo[C]: C => A = _ => a */ diff --git a/tests/pos/i6938.scala b/tests/pos/i6938.scala index 706aee5d3c1d..e58ab2829cf9 100644 --- a/tests/pos/i6938.scala +++ b/tests/pos/i6938.scala @@ -1,5 +1,5 @@ trait Foo[T] -object Foo with +object Foo: given [T]: Foo[Tuple1[T]] with {} given [T, U]: Foo[(T, U)] with {} given [T, U, V]: Foo[(T, U, V)] with {} \ No newline at end of file diff --git a/tests/pos/i7217.scala b/tests/pos/i7217.scala index 2a3c3f64fa6a..1c2a92c731b7 100644 --- a/tests/pos/i7217.scala +++ b/tests/pos/i7217.scala @@ -1,4 +1,4 @@ -class Foo(p1: String, p2: String) with +class Foo(p1: String, p2: String): def this(p1: String) = this(p1, "blah") val x = { Foo("blah", "hah") } diff --git a/tests/pos/i7359.scala b/tests/pos/i7359.scala index 97908254e99d..697b20b23cd0 100644 --- a/tests/pos/i7359.scala +++ b/tests/pos/i7359.scala @@ -1,95 +1,95 @@ package test -trait ObjectInterface with +trait ObjectInterface: def equals(obj: Any): Boolean def hashCode(): Int def toString(): String -trait SAMPlain with +trait SAMPlain: def first(): String -trait SAMPlainWithOverriddenObjectMethods with +trait SAMPlainWithOverriddenObjectMethods: def first(): String def equals(obj: Any): Boolean def hashCode(): Int def toString(): String -trait SAMPlainWithExtends extends ObjectInterface with +trait SAMPlainWithExtends extends ObjectInterface: def first(): String -trait SAMPlainWithExtendsAndOverride extends ObjectInterface with +trait SAMPlainWithExtendsAndOverride extends ObjectInterface: def first(): String override def equals(obj: Any): Boolean override def hashCode(): Int override def toString(): String -trait SAMPlainCovariantOut[+O] with +trait SAMPlainCovariantOut[+O]: def first(): O -trait SAMCovariantOut[+O] with +trait SAMCovariantOut[+O]: def first(): O def equals(obj: Any): Boolean def hashCode(): Int def toString(): String -trait SAMCovariantOutExtends[+O] extends ObjectInterface with +trait SAMCovariantOutExtends[+O] extends ObjectInterface: def first(): O -trait SAMCovariantOutExtendsAndOverride[+O] extends ObjectInterface with +trait SAMCovariantOutExtendsAndOverride[+O] extends ObjectInterface: def first(): O override def equals(obj: Any): Boolean override def hashCode(): Int override def toString(): String -trait SAMPlainContravariantIn[-I] with +trait SAMPlainContravariantIn[-I]: def first(in: I): Unit -trait SAMContravariantIn[-I] with +trait SAMContravariantIn[-I]: def first(in: I): Unit def equals(obj: Any): Boolean def hashCode(): Int def toString(): String -trait SAMContravariantInExtends[-I] extends ObjectInterface with +trait SAMContravariantInExtends[-I] extends ObjectInterface: def first(in: I): Unit -trait SAMContravariantInExtendsAndOverride[-I] extends ObjectInterface with +trait SAMContravariantInExtendsAndOverride[-I] extends ObjectInterface: def first(in: I): Unit override def equals(obj: Any): Boolean override def hashCode(): Int override def toString(): String -trait SAMPlainInvariant[T] with +trait SAMPlainInvariant[T]: def first(in: T): T -trait SAMInvariant[T] with +trait SAMInvariant[T]: def first(in: T): T def equals(obj: Any): Boolean def hashCode(): Int def toString(): String -trait SAMInvariantExtends[T] extends ObjectInterface with +trait SAMInvariantExtends[T] extends ObjectInterface: def first(in: T): T -trait SAMInvariantExtendsAndOverride[T] extends ObjectInterface with +trait SAMInvariantExtendsAndOverride[T] extends ObjectInterface: def first(in: T): T override def equals(obj: Any): Boolean override def hashCode(): Int override def toString(): String -trait SAMPlainInOut[-I, +O] with +trait SAMPlainInOut[-I, +O]: def first(in: I): O -trait SAMInOut[-I, +O] with +trait SAMInOut[-I, +O]: def first(in: I): O def equals(obj: Any): Boolean def hashCode(): Int def toString(): String -trait SAMInOutExtends[-I, +O] extends ObjectInterface with +trait SAMInOutExtends[-I, +O] extends ObjectInterface: def first(in: I): O -trait SAMInOutExtendsAndOverride[-I, +O] extends ObjectInterface with +trait SAMInOutExtendsAndOverride[-I, +O] extends ObjectInterface: def first(in: I): O override def equals(obj: Any): Boolean override def hashCode(): Int @@ -99,13 +99,13 @@ type CustomString = String type CustomBoolean = Boolean type CustomInt = Int -trait SAMWithCustomAliases with +trait SAMWithCustomAliases: def first(): String def equals(obj: Any): CustomBoolean def hashCode(): CustomInt def toString(): CustomString -object Main with +object Main: def main(args: Array[String]) = val samPlain : SAMPlain = () => "Hello, World!" val samPlainWithOverriddenObjectMethods: SAMPlainWithOverriddenObjectMethods = () => "Hello, World!" diff --git a/tests/pos/i7375.scala b/tests/pos/i7375.scala index 96bdd0b41b50..9da548f99ce7 100644 --- a/tests/pos/i7375.scala +++ b/tests/pos/i7375.scala @@ -1,10 +1,10 @@ -trait Entity[M, T, P] with +trait Entity[M, T, P]: extension (me: M) def receive(sender: T)(msg: P)(using Entity[T, M, P]): Unit extension (me: M) def name(): String class GreetingPerson(private val name: String) -object GreetingPerson with +object GreetingPerson: given GreetingPersonEntity: Entity[GreetingPerson, GreetedPerson, String] with extension (me: GreetingPerson) def receive(sender: GreetedPerson)(msg: String)(using Entity[GreetedPerson, GreetingPerson, String]): Unit = println(f"Thanks for saying $msg, ${sender.name()}") @@ -14,7 +14,7 @@ object GreetingPerson with class GreetedPerson(private val name: String) -object GreetedPerson with +object GreetedPerson: given GreetedPersonEntity: Entity[GreetedPerson, GreetingPerson, String] with extension (me: GreetedPerson) def receive(sender: GreetingPerson)(msg: String)(using Entity[GreetingPerson, GreetedPerson, String]): Unit = println(f"Thanks for saying $msg, ${sender.name()}") diff --git a/tests/pos/i7413.scala b/tests/pos/i7413.scala index 5b04cee445cf..ebc0c5b2777a 100644 --- a/tests/pos/i7413.scala +++ b/tests/pos/i7413.scala @@ -2,20 +2,20 @@ import scala.language.implicitConversions trait Fixture[A] extends Conversion[0, A] -trait TestFramework[A] with +trait TestFramework[A]: extension (testName: String) def in(test: Fixture[A] ?=> Unit): Unit = ??? -trait Greeter with +trait Greeter: def greet(name: String): String = s"Hello $name" case class MyFixture(name: String, greeter: Greeter) -object Test1 with +object Test1: given conv: Conversion[0, Greeter] with def apply(x: 0): Greeter = ??? val g: Greeter = 0 -class MyTest extends TestFramework[MyFixture] with +class MyTest extends TestFramework[MyFixture]: "say hello" in { assert(0.greeter.greet(0.name) == s"Hello ${0.name}") } diff --git a/tests/pos/i7428.scala b/tests/pos/i7428.scala index e1ab2ffd91e8..b702c7146cc5 100644 --- a/tests/pos/i7428.scala +++ b/tests/pos/i7428.scala @@ -1,5 +1,5 @@ -class ABug with - enum Tag with +class ABug: + enum Tag: case first import Tag.first val xx = first diff --git a/tests/pos/i7648.scala b/tests/pos/i7648.scala index 13dd1376c9e5..12e4a025f859 100644 --- a/tests/pos/i7648.scala +++ b/tests/pos/i7648.scala @@ -11,7 +11,7 @@ class Stream[+F[_], +A] { } } -object Test with +object Test: implicit val ioMonad: Monad[IO] = null diff --git a/tests/pos/i7700.scala b/tests/pos/i7700.scala index 56151dc5554c..fdcfc23c9105 100644 --- a/tests/pos/i7700.scala +++ b/tests/pos/i7700.scala @@ -1,12 +1,12 @@ package test -trait Show[-A] with +trait Show[-A]: def show(a: A): String -object Macros with +object Macros: extension (sc: StringContext) inline def show(args: =>Any*): String = ??? -object Show with +object Show: extension [A] (a: A) def show(using S: Show[A]): String = S.show(a) export Macros.show \ No newline at end of file diff --git a/tests/pos/i7757.scala b/tests/pos/i7757.scala index f1c7b2b48122..cebd6fc3ad84 100644 --- a/tests/pos/i7757.scala +++ b/tests/pos/i7757.scala @@ -1,7 +1,7 @@ val m: Map[Int, String] = ??? val _ = m.map((a, b) => a + b.length) -trait Foo with +trait Foo: def g(f: ((Int, Int)) => Int): Int = 1 def g(f: ((Int, Int)) => (Int, Int)): String = "2" diff --git a/tests/pos/i7793.scala b/tests/pos/i7793.scala index f0c394208a07..3458315c48c5 100644 --- a/tests/pos/i7793.scala +++ b/tests/pos/i7793.scala @@ -1,4 +1,4 @@ -trait Foo with +trait Foo: def g(f: Int => Int): Int = 1 def g(using String)(f: Int => String): String = "2" diff --git a/tests/pos/i7807.scala b/tests/pos/i7807.scala index 36193f26a972..df8a41ddcf8d 100644 --- a/tests/pos/i7807.scala +++ b/tests/pos/i7807.scala @@ -1,4 +1,4 @@ -object Test with +object Test: def flip: (x: 0 | 1) => x.type match { case 0 => 1 case 1 => 0 } = ??? diff --git a/tests/pos/i8181.scala b/tests/pos/i8181.scala index 5afdf5950ba4..d36214c3068a 100644 --- a/tests/pos/i8181.scala +++ b/tests/pos/i8181.scala @@ -1,4 +1,4 @@ -object Main with +object Main: def main(args: Array[String]): Unit = extension (a: AnyRef) def putout(): Unit = println(a) diff --git a/tests/pos/i8182.scala b/tests/pos/i8182.scala index 8679ad224ec1..9acf2941c570 100644 --- a/tests/pos/i8182.scala +++ b/tests/pos/i8182.scala @@ -1,6 +1,6 @@ package example -trait Show[-A] with +trait Show[-A]: extension (a: A) def show: String given (using rec: Show[String]): Show[String] = ??? // must be Show[String] as the argument diff --git a/tests/pos/i8319.scala b/tests/pos/i8319.scala index 412d33260be1..d08ba85e7115 100644 --- a/tests/pos/i8319.scala +++ b/tests/pos/i8319.scala @@ -5,7 +5,7 @@ case class Lam[T,U]() extends Tree[Any] case class App[T,U]() extends Tree[Any] case class Var() extends Tree[Any] -object Branch with +object Branch: def unapply(branch: Lam[?,?] | App[?,?]): true = true private def foo(s: Option[Tree[?]]) = s match // seems to only occur in a nested pattern diff --git a/tests/pos/i8397.scala b/tests/pos/i8397.scala index e0e126d60687..d0b97f84129d 100644 --- a/tests/pos/i8397.scala +++ b/tests/pos/i8397.scala @@ -3,13 +3,13 @@ given foo(using x: Int): AnyRef with // #7859 -trait Lub2[A, B] with +trait Lub2[A, B]: type Output given [A <: C, B <: C, C]: Lub2[A, B] with type Output = C -trait Lub[Union] with +trait Lub[Union]: type Output given [A]: Lub[A] with diff --git a/tests/pos/i8530.scala b/tests/pos/i8530.scala index e0b1963cb7bc..2eab9f9e74c8 100644 --- a/tests/pos/i8530.scala +++ b/tests/pos/i8530.scala @@ -1,19 +1,19 @@ -object MyBoooleanUnapply with +object MyBoooleanUnapply: inline def unapply(x: Int): Boolean = true -object MyOptionUnapply with +object MyOptionUnapply: inline def unapply(x: Int): Option[Long] = Some(x) -object MyUnapplyImplicits with +object MyUnapplyImplicits: inline def unapply(x: Int)(using DummyImplicit): Option[Long] = Some(x) -object MyPolyUnapply with +object MyPolyUnapply: inline def unapply[T](x: T): Option[T] = Some(x) -object MySeqUnapply with +object MySeqUnapply: inline def unapplySeq(x: Int): Seq[Int] = Seq(x, x) -object MyWhiteboxUnapply with +object MyWhiteboxUnapply: transparent inline def unapply(x: Int): Option[Any] = Some(x) def test: Unit = diff --git a/tests/pos/i8623.scala b/tests/pos/i8623.scala index 3f505ca54f47..e0df48811e1c 100644 --- a/tests/pos/i8623.scala +++ b/tests/pos/i8623.scala @@ -1,6 +1,6 @@ -trait QC with - object tasty with +trait QC: + object tasty: type Tree extension (tree: Tree) def pos: Tree = ??? diff --git a/tests/pos/i8750.scala b/tests/pos/i8750.scala index 5fb9c68a8d75..a88cfb51acd2 100644 --- a/tests/pos/i8750.scala +++ b/tests/pos/i8750.scala @@ -1,4 +1,4 @@ -class Abc with +class Abc: opaque type Log = Double val v : Abc = new Abc \ No newline at end of file diff --git a/tests/pos/i8801.scala b/tests/pos/i8801.scala index 2b122340e3a7..f925a60dbfe3 100644 --- a/tests/pos/i8801.scala +++ b/tests/pos/i8801.scala @@ -1,4 +1,4 @@ -object Foo with +object Foo: locally { case class Baz() } diff --git a/tests/pos/i8843.scala b/tests/pos/i8843.scala index aac14dfa838b..d6744d4096f5 100644 --- a/tests/pos/i8843.scala +++ b/tests/pos/i8843.scala @@ -1,4 +1,4 @@ -class C with +class C: type X <: Tuple inline def f(c: C): Unit = { diff --git a/tests/pos/i8845.scala b/tests/pos/i8845.scala index c30fa6b51e8e..52e41cbc9605 100644 --- a/tests/pos/i8845.scala +++ b/tests/pos/i8845.scala @@ -1,4 +1,4 @@ -trait IntToLong with +trait IntToLong: def apply(v: Int) : Long inline def convert1( f: IntToLong) = ??? diff --git a/tests/pos/i8874.scala b/tests/pos/i8874.scala index a458e5c2ddc6..cc19ee330ac0 100644 --- a/tests/pos/i8874.scala +++ b/tests/pos/i8874.scala @@ -1,4 +1,4 @@ -trait Abc with +trait Abc: opaque type Log = Double class AbcClass extends Abc diff --git a/tests/pos/i8892.scala b/tests/pos/i8892.scala index 6763e8fdc895..f08b12341d3b 100644 --- a/tests/pos/i8892.scala +++ b/tests/pos/i8892.scala @@ -1,7 +1,7 @@ -trait Reporter with +trait Reporter: def report(m: String): Unit -class Dummy extends Reporter with +class Dummy extends Reporter: def report(m: String) = () object ABug { diff --git a/tests/pos/i8920/Qu_1.scala b/tests/pos/i8920/Qu_1.scala index 08c6e3e90ffa..c0ddfdcaae8e 100644 --- a/tests/pos/i8920/Qu_1.scala +++ b/tests/pos/i8920/Qu_1.scala @@ -1,9 +1,9 @@ package scala.collection.mutable -class Qu[A] protected (array: Array[AnyRef], start: Int, end: Int) with +class Qu[A] protected (array: Array[AnyRef], start: Int, end: Int): def this(initialSize: Int = ArrayDeque.DefaultInitialSize) = this(ArrayDeque.alloc(initialSize), start = 0, end = 0) -object Qu with +object Qu: def f[A](array: Array[AnyRef], start: Int, end: Int) = 1 def f[A](initialSize: Int = 1) = 2 diff --git a/tests/pos/i8927.scala b/tests/pos/i8927.scala index 1cf45c0045fa..2dfb419abab3 100644 --- a/tests/pos/i8927.scala +++ b/tests/pos/i8927.scala @@ -1,14 +1,14 @@ import scala.language.implicitConversions -trait Eq[k <: AnyKind, K[_ <: k]] with +trait Eq[k <: AnyKind, K[_ <: k]]: extension [A <: k, B <: k](k: K[A]) def isEq (k2: K[B]): Eq.GEQ[k, K, A, B] -object Eq with - enum GEQ[k <: AnyKind, K[_ <: k], A <: k, B <: k] with +object Eq: + enum GEQ[k <: AnyKind, K[_ <: k], A <: k, B <: k]: case Y[k <: AnyKind, K[_ <: k], A <: k](res: K[A]) extends GEQ[k, K, A, A] case N() -sealed trait DPair[k <: AnyKind, K[_ <: k], +V[_ <: k]] with +sealed trait DPair[k <: AnyKind, K[_ <: k], +V[_ <: k]]: type A <: k val key: K[A] val value: V[A] @@ -16,8 +16,8 @@ sealed trait DPair[k <: AnyKind, K[_ <: k], +V[_ <: k]] with case y: Eq.GEQ.Y[k, K, A] => Some(value) case _ => None -object DPair with +object DPair: given pair [k, K[_ <: k], V[_ <: k], C <: k]: Conversion[(K[C], V[C]), DPair[k, K, V]] = tup => - case class dpair(key: K[C], value: V[C]) extends DPair[k, K, V] with + case class dpair(key: K[C], value: V[C]) extends DPair[k, K, V]: type A = C dpair(tup._1, tup._2) diff --git a/tests/pos/i8968.scala b/tests/pos/i8968.scala index 915eb2681561..ac76dd5ca56c 100644 --- a/tests/pos/i8968.scala +++ b/tests/pos/i8968.scala @@ -1,7 +1,7 @@ -object Foo with +object Foo: inline def get = 0 -object Bar with +object Bar: export Foo._ val v = Bar.get diff --git a/tests/pos/i8972.scala b/tests/pos/i8972.scala index ffa003d65424..e4678718aa4f 100644 --- a/tests/pos/i8972.scala +++ b/tests/pos/i8972.scala @@ -1,7 +1,7 @@ -trait Num with +trait Num: type Nat -object IsInt with +object IsInt: def unapply(using num: Num)(sc: num.Nat): Option[Int] = ??? def test(using num: Num)(x: num.Nat) = diff --git a/tests/pos/i8997.scala b/tests/pos/i8997.scala index 9e5fba6a77cf..4a34902b97c4 100644 --- a/tests/pos/i8997.scala +++ b/tests/pos/i8997.scala @@ -1,4 +1,4 @@ -object Foo with +object Foo: def unapply(n: Int)(using x: DummyImplicit)(using y: Int): Option[Int] = ??? def test = diff --git a/tests/pos/i9052/A.scala b/tests/pos/i9052/A.scala index cc24250c7c91..1ff6fa0df82e 100644 --- a/tests/pos/i9052/A.scala +++ b/tests/pos/i9052/A.scala @@ -1,4 +1,4 @@ -object impl with +object impl: case object UNone import impl._ diff --git a/tests/pos/i9069/Wrapper.scala b/tests/pos/i9069/Wrapper.scala index f25c128a5f4c..1c3952b683e1 100644 --- a/tests/pos/i9069/Wrapper.scala +++ b/tests/pos/i9069/Wrapper.scala @@ -1,4 +1,4 @@ sealed trait Foo -object Foo with +object Foo: case object Baz extends Foo case class Bar(x: Int) extends Foo diff --git a/tests/pos/i9103.scala b/tests/pos/i9103.scala index e84d194d299f..c33eb8166201 100644 --- a/tests/pos/i9103.scala +++ b/tests/pos/i9103.scala @@ -1,4 +1,4 @@ -object a with +object a: trait Foo[T] given Foo[Unit] = ??? diff --git a/tests/pos/i9213.scala b/tests/pos/i9213.scala index e8fc2a862292..1a6488c4c0fb 100644 --- a/tests/pos/i9213.scala +++ b/tests/pos/i9213.scala @@ -1,5 +1,5 @@ trait A(a: Any, b: Int) -trait B(a: Any, b: Int) with +trait B(a: Any, b: Int): var x = 0 class C(a: String, b: Int) diff --git a/tests/pos/i9307.scala b/tests/pos/i9307.scala index 4b5f7fae1708..a795f1d3fc62 100644 --- a/tests/pos/i9307.scala +++ b/tests/pos/i9307.scala @@ -1,4 +1,4 @@ -class Foo with +class Foo: private var foo1: Int = _ private var foo2: Array[Int] = _ private[this] var foo3: Array[Int] = _ diff --git a/tests/pos/i9342b.scala b/tests/pos/i9342b.scala index 39e224d528e0..e317391f9bb8 100644 --- a/tests/pos/i9342b.scala +++ b/tests/pos/i9342b.scala @@ -1,4 +1,4 @@ -trait Label[A] with +trait Label[A]: def apply(v: A): String given [A]: Label[A] = _.toString diff --git a/tests/pos/i9342c.scala b/tests/pos/i9342c.scala index 27efc0baabdc..eed9d45326f1 100644 --- a/tests/pos/i9342c.scala +++ b/tests/pos/i9342c.scala @@ -1,4 +1,4 @@ -trait Label[A] with +trait Label[A]: def apply(v: A): String def g[A]: Label[A] = _.toString diff --git a/tests/pos/i9352.scala b/tests/pos/i9352.scala index ee45cdebee2a..db757b48b027 100644 --- a/tests/pos/i9352.scala +++ b/tests/pos/i9352.scala @@ -1,6 +1,6 @@ abstract class Foo[B] extends Bar[B] -trait Bar[A] with +trait Bar[A]: self: Foo[A] => def foo : Unit = bar(???) diff --git a/tests/pos/i9457.scala b/tests/pos/i9457.scala index 32550e351ebb..c210e3dc92ff 100644 --- a/tests/pos/i9457.scala +++ b/tests/pos/i9457.scala @@ -1,4 +1,4 @@ -object inlinetuple with +object inlinetuple: def test: Int = f((1, 2)) inline def f(inline p: (Int, Int)): Int = diff --git a/tests/pos/i9464.scala b/tests/pos/i9464.scala index d0a94ed3dd9f..56cef7aedff8 100644 --- a/tests/pos/i9464.scala +++ b/tests/pos/i9464.scala @@ -1,4 +1,4 @@ -trait T with +trait T: type X def x: X diff --git a/tests/pos/i9530.scala b/tests/pos/i9530.scala index aa5e0d1b04e0..32b2f26dbd6c 100644 --- a/tests/pos/i9530.scala +++ b/tests/pos/i9530.scala @@ -1,12 +1,12 @@ trait Food case class Banana(color: String) extends Food -trait Diet[A <: Animal] with +trait Diet[A <: Animal]: type F <: Food def food: Seq[F] trait Animal -object Animal with +object Animal: extension [A <: Animal](using diet: Diet[A])(animal: A) def food1 = diet.food extension [A <: Animal](animal: A)(using diet: Diet[A]) def food2 = diet.food diff --git a/tests/pos/i9562.scala b/tests/pos/i9562.scala index a1cd86a2993b..9f58ff309d3c 100644 --- a/tests/pos/i9562.scala +++ b/tests/pos/i9562.scala @@ -1,7 +1,7 @@ -class Foo with +class Foo: def foo = 23 -object Unrelated with +object Unrelated: extension (f: Foo) def g = f.foo // OK diff --git a/tests/pos/i9844.scala b/tests/pos/i9844.scala index f4c2427fde90..a660c5046c5b 100644 --- a/tests/pos/i9844.scala +++ b/tests/pos/i9844.scala @@ -1,4 +1,4 @@ -object test1 with +object test1: trait Foo[A] trait Baz[A] { @@ -8,13 +8,13 @@ object test1 with } } -object test2 with +object test2: - trait Foo with + trait Foo: private var f = "abc" trait Baz { - trait Bam with + trait Bam: val f = 0 trait Bar extends Bam { this: Foo => @@ -23,7 +23,7 @@ object test2 with } } -object test3 with +object test3: object DetSkipOctree { sealed trait Leaf [PL] sealed trait Branch[PL] diff --git a/tests/pos/i9967.scala b/tests/pos/i9967.scala index 0b506d5323df..4e915a27bfbf 100644 --- a/tests/pos/i9967.scala +++ b/tests/pos/i9967.scala @@ -1,6 +1,6 @@ import collection.mutable -class MaxSizeMap[K, V](maxSize: Int)(using o: Ordering[K]) with +class MaxSizeMap[K, V](maxSize: Int)(using o: Ordering[K]): val sortedMap: mutable.TreeMap[K, V] = mutable.TreeMap.empty[K, V](o) export sortedMap._ diff --git a/tests/pos/i9994.scala b/tests/pos/i9994.scala index d94e5d4d8f77..d2125fe07df9 100644 --- a/tests/pos/i9994.scala +++ b/tests/pos/i9994.scala @@ -1,7 +1,7 @@ package pkg -trait Foo with +trait Foo: def foo: this.type -final class Bar extends Foo with +final class Bar extends Foo: def foo: this.type = this diff --git a/tests/pos/indent.scala b/tests/pos/indent.scala index 9b389c360d1f..03502a26fe79 100644 --- a/tests/pos/indent.scala +++ b/tests/pos/indent.scala @@ -1,4 +1,4 @@ -object Test with +object Test: locally { var x = 0 @@ -82,7 +82,8 @@ object Test with x < 10 do () -class Test2 with self: Test2 => +class Test2: + self => def foo(x: Int) = if x < 0 then throw val ex = new AssertionError() @@ -96,17 +97,15 @@ class Test2 with self: Test2 => end x end Test2 -class Test3 with - self => +class Test3: + self => def foo = 1 -class Test4 with { val x = 5 } - import collection.mutable.HashMap -class Coder(words: List[String]) with +class Coder(words: List[String]): - class Foo with + class Foo: println() end Foo @@ -147,5 +146,5 @@ class Coder(words: List[String]) with } end Coder -object Test22 with +object Test22: def foo: Int = 22 \ No newline at end of file diff --git a/tests/pos/indent2.scala b/tests/pos/indent2.scala index 6df51b51cf81..bbe07dae959a 100644 --- a/tests/pos/indent2.scala +++ b/tests/pos/indent2.scala @@ -1,6 +1,6 @@ -object testindent with +object testindent: - class C with + class C: val x = 0 val c = new C diff --git a/tests/pos/indent4.scala b/tests/pos/indent4.scala index ee76ea84186c..fa80b62d7db4 100644 --- a/tests/pos/indent4.scala +++ b/tests/pos/indent4.scala @@ -1,4 +1,4 @@ -object testindent with +object testindent: if (true) val x = 1 diff --git a/tests/pos/inline-val-constValue-1.scala b/tests/pos/inline-val-constValue-1.scala index f9cec9f466ad..efd482cd5c09 100644 --- a/tests/pos/inline-val-constValue-1.scala +++ b/tests/pos/inline-val-constValue-1.scala @@ -1,6 +1,6 @@ import compiletime._ -class C with +class C: type X <: Tuple def test: Unit = diff --git a/tests/pos/inline-val-constValue-2.scala b/tests/pos/inline-val-constValue-2.scala index 2ff62a31d34f..33ae23069fa2 100644 --- a/tests/pos/inline-val-constValue-2.scala +++ b/tests/pos/inline-val-constValue-2.scala @@ -1,6 +1,6 @@ import compiletime._ -class C with +class C: type N <: Int def test: Unit = diff --git a/tests/pos/main-method-scheme-class-based.scala b/tests/pos/main-method-scheme-class-based.scala index 41b51432afe6..86393d05c953 100644 --- a/tests/pos/main-method-scheme-class-based.scala +++ b/tests/pos/main-method-scheme-class-based.scala @@ -11,7 +11,7 @@ import collection.mutable * or `command.argsGetter` if is a final varargs parameter, * - a call to `command.run` with the closure of user-main applied to all arguments. */ -trait MainAnnotation extends StaticAnnotation with +trait MainAnnotation extends StaticAnnotation: /** The class used for argument string parsing. E.g. `scala.util.CommandLineParser.FromString`, * but could be something else @@ -25,7 +25,7 @@ trait MainAnnotation extends StaticAnnotation with def command(args: Array[String]): Command /** A class representing a command to run */ - abstract class Command with + abstract class Command: /** The getter for the next argument of type `T` */ def argGetter[T](argName: String, fromString: ArgumentParser[T], defaultValue: Option[T] = None): () => T @@ -42,12 +42,12 @@ end MainAnnotation //Sample main class, can be freely implemented: -class main extends MainAnnotation with +class main extends MainAnnotation: type ArgumentParser[T] = util.CommandLineParser.FromString[T] type MainResultType = Any - def command(args: Array[String]): Command = new Command with + def command(args: Array[String]): Command = new Command: /** A buffer of demanded argument names, plus * "?" if it has a default @@ -135,7 +135,7 @@ end main // Sample main method -object myProgram with +object myProgram: /** Adds two numbers */ @main def add(num: Int, inc: Int = 1): Unit = @@ -145,7 +145,7 @@ end myProgram // Compiler generated code: -object add extends main with +object add extends main: def main(args: Array[String]) = val cmd = command(args) val arg1 = cmd.argGetter[Int]("num", summon[ArgumentParser[Int]]) diff --git a/tests/pos/main-method-scheme.scala b/tests/pos/main-method-scheme.scala index df6ec31692d2..c65f7c928efd 100644 --- a/tests/pos/main-method-scheme.scala +++ b/tests/pos/main-method-scheme.scala @@ -1,7 +1,7 @@ import annotation.StaticAnnotation import collection.mutable -trait MainAnnotation extends StaticAnnotation with +trait MainAnnotation extends StaticAnnotation: type ArgumentParser[T] @@ -18,7 +18,7 @@ end MainAnnotation //Sample main class, can be freely implemented: -class main(progName: String, args: Array[String], docComment: String) extends MainAnnotation with +class main(progName: String, args: Array[String], docComment: String) extends MainAnnotation: def this() = this("", Array(), "") @@ -106,7 +106,7 @@ end main // Sample main method -object myProgram with +object myProgram: /** Adds two numbers */ @main def add(num: Int, inc: Int = 1) = @@ -116,7 +116,7 @@ end myProgram // Compiler generated code: -object add with +object add: def main(args: Array[String]) = val cmd = new main("add", args, "Adds two numbers") val arg1 = cmd.getArg[Int]("num", summon[cmd.ArgumentParser[Int]]) diff --git a/tests/pos/matches.scala b/tests/pos/matches.scala index 3f724dbef756..7b590d5bb422 100644 --- a/tests/pos/matches.scala +++ b/tests/pos/matches.scala @@ -1,5 +1,5 @@ package matches -object Test with +object Test: 2 min 3 match case 2 => "OK" case 3 => "?" diff --git a/tests/pos/matrixOps.scala b/tests/pos/matrixOps.scala index 44fc5bc2052d..ab96a09389a5 100644 --- a/tests/pos/matrixOps.scala +++ b/tests/pos/matrixOps.scala @@ -1,4 +1,4 @@ -object Test with +object Test: type Matrix = Array[Array[Double]] type Vector = Array[Double] diff --git a/tests/pos/opaques-queue.scala b/tests/pos/opaques-queue.scala index b03b9c8e0210..079ef7fde4f6 100644 --- a/tests/pos/opaques-queue.scala +++ b/tests/pos/opaques-queue.scala @@ -1,11 +1,11 @@ class Elem -trait QueueSignature with +trait QueueSignature: type Queue def empty: Queue def append(q: Queue, e: Elem): Queue def pop(q: Queue): Option[(Elem, Queue)] val QueueModule: QueueSignature = - object QueueImpl extends QueueSignature with + object QueueImpl extends QueueSignature: type Queue = (List[Elem], List[Elem]) def empty = (Nil, Nil) def append(q: Queue, e: Elem): Queue = (q._1, e :: q._2) @@ -15,7 +15,7 @@ val QueueModule: QueueSignature = case (Nil, ys) => pop((ys.reverse, Nil)) QueueImpl -object queues with +object queues: opaque type Queue = (List[Elem], List[Elem]) def empty = (Nil, Nil) def append(q: Queue, e: Elem): Queue = (q._1, e :: q._2) diff --git a/tests/pos/packagings.scala b/tests/pos/packagings.scala index 96ce1a66e34c..47e1df204b34 100644 --- a/tests/pos/packagings.scala +++ b/tests/pos/packagings.scala @@ -1,10 +1,10 @@ package foo: package bar: - object A with + object A: def foo = 1 end bar end foo package baz: - object B with + object B: def f = foo.bar.A.foo end baz diff --git a/tests/pos/postconditions.scala b/tests/pos/postconditions.scala index c492231d517f..90117c17b207 100644 --- a/tests/pos/postconditions.scala +++ b/tests/pos/postconditions.scala @@ -1,4 +1,4 @@ -object PostConditions with +object PostConditions: opaque type WrappedResult[T] = T def result[T](using r: WrappedResult[T]): T = r @@ -8,6 +8,6 @@ object PostConditions with assert(condition) x -object Test with +object Test: import PostConditions.{ensuring, result} val s = List(1, 2, 3).sum.ensuring(result == 6) diff --git a/tests/pos/reference/adts.scala b/tests/pos/reference/adts.scala index e93bb843f97c..41ea6660638e 100644 --- a/tests/pos/reference/adts.scala +++ b/tests/pos/reference/adts.scala @@ -1,25 +1,25 @@ package adts -object t1 with +object t1: - enum Option[+T] with + enum Option[+T]: case Some[T](x: T) extends Option[T] case None -object t2 with +object t2: - enum Option[+T] with + enum Option[+T]: case Some[T](x: T) extends Option[T] case None extends Option[Nothing] -enum Color(val rgb: Int) with +enum Color(val rgb: Int): case Red extends Color(0xFF0000) case Green extends Color(0x00FF00) case Blue extends Color(0x0000FF) case Mix(mix: Int) extends Color(mix) -object t3 with +object t3: - enum Option[+T] with + enum Option[+T]: case Some[T](x: T) extends Option[T] case None @@ -27,6 +27,6 @@ object t3 with case None => false case some => true - object Option with + object Option: def apply[T >: Null](x: T): Option[T] = if (x == null) None else Some(x) diff --git a/tests/pos/reference/auto-param-tupling.scala b/tests/pos/reference/auto-param-tupling.scala index c2dd9889fa98..c32173867fe6 100644 --- a/tests/pos/reference/auto-param-tupling.scala +++ b/tests/pos/reference/auto-param-tupling.scala @@ -1,6 +1,6 @@ package autoParamTupling -object t1 with +object t1: val xs: List[(Int, Int)] = ??? xs.map { diff --git a/tests/pos/reference/compile-time.scala b/tests/pos/reference/compile-time.scala index 119d16f51718..32ea7660c898 100644 --- a/tests/pos/reference/compile-time.scala +++ b/tests/pos/reference/compile-time.scala @@ -1,6 +1,6 @@ package compiletime -class Test with +class Test: import scala.compiletime.{constValue, erasedValue, S} trait Nat diff --git a/tests/pos/reference/delegate-match.scala b/tests/pos/reference/delegate-match.scala index bf026b2d4ea8..3ab00cc46701 100644 --- a/tests/pos/reference/delegate-match.scala +++ b/tests/pos/reference/delegate-match.scala @@ -1,6 +1,6 @@ package implicitmatch -class Test extends App with +class Test extends App: import scala.collection.immutable.{TreeSet, HashSet} import scala.compiletime.summonFrom diff --git a/tests/pos/reference/delegates.scala b/tests/pos/reference/delegates.scala index 35bd6ebdddff..88002d939330 100644 --- a/tests/pos/reference/delegates.scala +++ b/tests/pos/reference/delegates.scala @@ -1,30 +1,30 @@ -class Common with +class Common: - trait Ord[T] with + trait Ord[T]: extension (x: T) def compareTo(y: T): Int extension (x: T) def < (y: T) = x.compareTo(y) < 0 extension (x: T) def > (y: T) = x.compareTo(y) > 0 - trait Convertible[From, To] with + trait Convertible[From, To]: extension (x: From) def convert: To - trait SemiGroup[T] with + trait SemiGroup[T]: extension (x: T) def combine(y: T): T - trait Monoid[T] extends SemiGroup[T] with + trait Monoid[T] extends SemiGroup[T]: def unit: T - trait Functor[F[_]] with + trait Functor[F[_]]: extension [A](x: F[A]) def map[B](f: A => B): F[B] - trait Monad[F[_]] extends Functor[F] with + trait Monad[F[_]] extends Functor[F]: extension [A](x: F[A]) def flatMap[B](f: A => F[B]): F[B] extension [A](x: F[A]) def map[B](f: A => B) = x.flatMap(f `andThen` pure) def pure[A](x: A): F[A] end Common -object Instances extends Common with +object Instances extends Common: given intOrd: Ord[Int] with extension (x: Int) def compareTo(y: Int) = @@ -64,7 +64,7 @@ object Instances extends Common with def maximum[T](xs: List[T])(using Ord[T]): T = xs.reduceLeft((x, y) => if (x < y) y else x) - def descending[T](using asc: Ord[T]): Ord[T] = new Ord[T] with + def descending[T](using asc: Ord[T]): Ord[T] = new Ord[T]: extension (x: T) def compareTo(y: T) = asc.compareTo(y)(x) def minimum[T](xs: List[T])(using Ord[T]) = @@ -85,20 +85,20 @@ object Instances extends Common with class B val ab: (x: A, y: B) ?=> Int = (a: A, b: B) ?=> 22 - trait TastyAPI with + trait TastyAPI: type Symbol - trait SymDeco with + trait SymDeco: extension (sym: Symbol) def name: String given symDeco: SymDeco - object TastyImpl extends TastyAPI with + object TastyImpl extends TastyAPI: type Symbol = String given symDeco: SymDeco with extension (sym: Symbol) def name = sym class D[T] - class C(using ctx: Context) with + class C(using ctx: Context): def f() = locally { given Context = this.ctx @@ -121,14 +121,14 @@ object Instances extends Common with class Token(str: String) - object Token with + object Token: given StringToToken: Conversion[String, Token] with def apply(str: String): Token = new Token(str) val x: Token = "if" end Instances -object PostConditions with +object PostConditions: opaque type WrappedResult[T] = T def result[T](using x: WrappedResult[T]): T = x @@ -139,7 +139,7 @@ object PostConditions with x end PostConditions -object AnonymousInstances extends Common with +object AnonymousInstances extends Common: given Ord[Int] with extension (x: Int) def compareTo(y: Int) = if (x < y) -1 else if (x > y) +1 else 0 @@ -173,12 +173,12 @@ object AnonymousInstances extends Common with xs.foldLeft(summon[Monoid[T]].unit)(_.combine(_)) end AnonymousInstances -object Implicits extends Common with - implicit object IntOrd extends Ord[Int] with +object Implicits extends Common: + implicit object IntOrd extends Ord[Int]: extension (x: Int) def compareTo(y: Int) = if (x < y) -1 else if (x > y) +1 else 0 - class ListOrd[T: Ord] extends Ord[List[T]] with + class ListOrd[T: Ord] extends Ord[List[T]]: extension (xs: List[T]) def compareTo(ys: List[T]): Int = (xs, ys).match case (Nil, Nil) => 0 case (Nil, _) => -1 @@ -199,31 +199,31 @@ object Implicits extends Common with (implicit cmp: Ord[T]): T = xs.reduceLeft((x, y) => if (x < y) y else x) - def descending[T](implicit asc: Ord[T]): Ord[T] = new Ord[T] with + def descending[T](implicit asc: Ord[T]): Ord[T] = new Ord[T]: extension (x: T) def compareTo(y: T) = asc.compareTo(y)(x) def minimum[T](xs: List[T])(implicit cmp: Ord[T]) = maximum(xs)(descending) -object Test extends App with +object Test extends App: Instances.test() import PostConditions.{result, ensuring} val s = List(1, 2, 3).sum s.ensuring(result == 6) end Test -object Completions with +object Completions: class Future[T] class HttpResponse class StatusCode // The argument "magnet" type - enum CompletionArg with + enum CompletionArg: case Error(s: String) case Response(f: Future[HttpResponse]) case Status(code: Future[StatusCode]) - object CompletionArg with + object CompletionArg: // conversions defining the possible arguments to pass to `complete` // these always come with CompletionArg diff --git a/tests/pos/reference/extension-methods.scala b/tests/pos/reference/extension-methods.scala index 15c8da3f6586..daa187cafa50 100644 --- a/tests/pos/reference/extension-methods.scala +++ b/tests/pos/reference/extension-methods.scala @@ -1,4 +1,4 @@ -object ExtMethods with +object ExtMethods: case class Circle(x: Double, y: Double, radius: Double) @@ -44,7 +44,7 @@ object ExtMethods with val limit = smallest(n).max xs.zipWithIndex.collect { case (x, i) if x <= limit => i } - trait IntOps with + trait IntOps: extension (i: Int) def isZero: Boolean = i == 0 extension (i: Int) def safeMod(x: Int): Option[Int] = @@ -53,13 +53,13 @@ object ExtMethods with else Some(i % x) end IntOps - object IntOpsEx extends IntOps with + object IntOpsEx extends IntOps: extension (i: Int) def safeDiv(x: Int): Option[Int] = // extension method brought into scope via inheritance from IntOps if x.isZero then None else Some(i / x) - trait SafeDiv with + trait SafeDiv: import IntOpsEx._ // brings safeDiv and safeMod into scope extension (i: Int) def divide(d: Int) : Option[(Int, Int)] = @@ -73,19 +73,19 @@ object ExtMethods with given ops1: IntOps with {} // brings safeMod into scope 1.safeMod(2) - class Lst[T](xs: T*) with + class Lst[T](xs: T*): private val elems = xs.toList def foldLeft[U](x: U)(op: (U, T) => U): U = elems.foldLeft(x)(op) def ++ (other: Lst[T]): Lst[T] = Lst(elems ++ other.elems: _*) - trait Ord[T] with + trait Ord[T]: extension (x: T) def less (y: T): Boolean - object Ord with + object Ord: given Ord[Int] with extension (x: Int) def less (y: Int): Boolean = x < y end Ord - object Lst with + object Lst: extension [T](xs: Lst[Lst[T]]) def flatten: Lst[T] = xs.foldLeft(Lst())(_ ++ _) @@ -110,7 +110,7 @@ object ExtMethods with if n < s.length && s(n) != ch then position(ch, n + 1) else n - object DoubleOps with + object DoubleOps: extension (x: Double) def ** (exponent: Int): Double = require(exponent > 0) if exponent == 0 then 1 else x * (x ** (exponent - 1)) diff --git a/tests/pos/reference/structural-closeable.scala b/tests/pos/reference/structural-closeable.scala index c396555ac6ab..771a6ae4ebc8 100644 --- a/tests/pos/reference/structural-closeable.scala +++ b/tests/pos/reference/structural-closeable.scala @@ -2,10 +2,10 @@ type Closeable = { def close(): Unit } -class FileInputStream with +class FileInputStream: def close(): Unit = () -class Channel with +class Channel: def close(): Unit = () import scala.reflect.Selectable.reflectiveSelectable diff --git a/tests/pos/refinements.scala b/tests/pos/refinements.scala index c59524e91924..3e509228584d 100644 --- a/tests/pos/refinements.scala +++ b/tests/pos/refinements.scala @@ -10,10 +10,6 @@ trait UU { type UX val u: UX val x: this.type & { type UX = Int } - val x1: this.type { type UX = Int } - val x2: this.type with { type UX = Int } - val x3: this.type with - type UX = Int val y: Int = x.u val z: x.UX = y } diff --git a/tests/pos/single-case.scala b/tests/pos/single-case.scala index 82466ec31733..2552f05129a6 100644 --- a/tests/pos/single-case.scala +++ b/tests/pos/single-case.scala @@ -1,4 +1,4 @@ -object test with +object test: try println("hi") diff --git a/tests/pos/t5856b.scala b/tests/pos/t5856b.scala index 162bc5971d6b..b266aa6fad6a 100644 --- a/tests/pos/t5856b.scala +++ b/tests/pos/t5856b.scala @@ -1,3 +1,3 @@ -class Test with +class Test: def test = f("a" == s"a") inline def f(inline b: Boolean): Boolean = !b diff --git a/tests/pos/targetName-infer-result.scala b/tests/pos/targetName-infer-result.scala index 42da8d36b457..7e732395a483 100644 --- a/tests/pos/targetName-infer-result.scala +++ b/tests/pos/targetName-infer-result.scala @@ -1,23 +1,23 @@ import annotation.targetName -enum Tree with +enum Tree: case Bind(sym: Symbol, body: Tree) class Symbol -object Test1 with - abstract class TreeAccumulator[X] with +object Test1: + abstract class TreeAccumulator[X]: def app(x: X, tree: Tree): X def app(x: X, trees: List[Tree]): X = ??? - val acc = new TreeAccumulator[List[Symbol]] with + val acc = new TreeAccumulator[List[Symbol]]: def app(syms: List[Symbol], tree: Tree) = tree match case Tree.Bind(sym, body) => app(sym :: syms, body) -object Test2 with - abstract class TreeAccumulator[X] with +object Test2: + abstract class TreeAccumulator[X]: @targetName("apply") def app(x: X, tree: Tree): X def app(x: X, trees: List[Tree]): X = ??? - val acc = new TreeAccumulator[List[Symbol]] with + val acc = new TreeAccumulator[List[Symbol]]: @targetName("apply") def app(syms: List[Symbol], tree: Tree) = tree match case Tree.Bind(sym, body) => app(sym :: syms, body) diff --git a/tests/pos/targetName-override.scala b/tests/pos/targetName-override.scala index 202f0a272ca5..a15ce5594a76 100644 --- a/tests/pos/targetName-override.scala +++ b/tests/pos/targetName-override.scala @@ -1,11 +1,11 @@ import scala.annotation.targetName -class A with +class A: @targetName("ff") def f(x: => Int): Int = x def f(x: => String): Int = x.length -class B extends A with +class B extends A: @targetName("ff") override def f(x: => Int): Int = x // OK override def f(x: => String): Int = x.length // OK diff --git a/tests/pos/targetName-refine.scala b/tests/pos/targetName-refine.scala index ae6206a18de0..eaa02b8b7976 100644 --- a/tests/pos/targetName-refine.scala +++ b/tests/pos/targetName-refine.scala @@ -1,7 +1,7 @@ import annotation.targetName -trait T with +trait T: @targetName("f2") def f: Any -class C extends T with +class C extends T: @targetName("f2") def f: Int = 1 val x: T { def f: Int } = C() diff --git a/tests/pos/tasty-tags-obscure.scala b/tests/pos/tasty-tags-obscure.scala index 8a73d714272e..cd883ee0aeba 100644 --- a/tests/pos/tasty-tags-obscure.scala +++ b/tests/pos/tasty-tags-obscure.scala @@ -1,15 +1,15 @@ -object ObscureTasty with +object ObscureTasty: def foo(f: [t] => List[t] ?=> Unit) = ??? def test1 = foo([t] => (a: List[t]) ?=> ()) // POLYtype => GIVENMETHODType def bar(f: [t] => List[t] => Unit) = ??? def test2 = bar([t] => (a: List[t]) => ()) // POLYtype => METHODType - class Bar with + class Bar: final val bar = "Bar.bar" - class Foo extends Bar with - object A with + class Foo extends Bar: + object A: def unapply(a: Any): Some[Foo.super.bar.type] = ??? def foo = diff --git a/tests/pos/typeclass-encoding3.scala b/tests/pos/typeclass-encoding3.scala index 7ae34427acb9..363826d2d6bd 100644 --- a/tests/pos/typeclass-encoding3.scala +++ b/tests/pos/typeclass-encoding3.scala @@ -45,7 +45,7 @@ object Test { class Str(val s: String) extends Monoid def combine(that: Str): Str = new Str(this.s + that.s) - object Str with + object Str: def unit = "" extension for String : Monoid diff --git a/tests/pos/widen-union.scala b/tests/pos/widen-union.scala index 6cd2e7787660..b0b64f0dc6c6 100644 --- a/tests/pos/widen-union.scala +++ b/tests/pos/widen-union.scala @@ -1,10 +1,10 @@ -object Test1 with +object Test1: val x: Int | String = 1 val y = x val z: Int | String = y -object Test2 with +object Test2: type Sig = Int | String def consistent(x: Sig, y: Sig): Boolean = ???// x == y @@ -12,7 +12,7 @@ object Test2 with xs.corresponds(ys)(consistent) // OK || xs.corresponds(ys)(consistent(_, _)) // error, found: Any, required: Int | String -object Test3 with +object Test3: def g[X](x: X | String): Int = ??? def y: Boolean | String = ??? diff --git a/tests/run-custom-args/tasty-inspector/i10359.scala b/tests/run-custom-args/tasty-inspector/i10359.scala index c2c9dad128a0..b724d0431b4a 100644 --- a/tests/run-custom-args/tasty-inspector/i10359.scala +++ b/tests/run-custom-args/tasty-inspector/i10359.scala @@ -33,7 +33,7 @@ object Test { } } -class TestInspector() extends TastyInspector with +class TestInspector() extends TastyInspector: protected def processCompilationUnit(using Quotes)(root: quotes.reflect.Tree): Unit = import quotes.reflect._ diff --git a/tests/run-custom-args/tasty-inspector/i8163.scala b/tests/run-custom-args/tasty-inspector/i8163.scala index e2bfba37aede..2ac769b321f1 100644 --- a/tests/run-custom-args/tasty-inspector/i8163.scala +++ b/tests/run-custom-args/tasty-inspector/i8163.scala @@ -20,7 +20,7 @@ object Test { } } -class TestInspector() extends TastyInspector with +class TestInspector() extends TastyInspector: protected def processCompilationUnit(using Quotes)(root: quotes.reflect.Tree): Unit = inspectClass(root) diff --git a/tests/run-custom-args/tasty-inspector/i8460.scala b/tests/run-custom-args/tasty-inspector/i8460.scala index 4e1c590cbf11..4f2d9ba6df44 100644 --- a/tests/run-custom-args/tasty-inspector/i8460.scala +++ b/tests/run-custom-args/tasty-inspector/i8460.scala @@ -33,7 +33,7 @@ object Test { } } -class TestInspector_Children() extends TastyInspector with +class TestInspector_Children() extends TastyInspector: var kids: List[String] = Nil diff --git a/tests/run-custom-args/tasty-inspector/i9970.scala b/tests/run-custom-args/tasty-inspector/i9970.scala index 6bf79569cbfd..fc76ea5e0fb5 100644 --- a/tests/run-custom-args/tasty-inspector/i9970.scala +++ b/tests/run-custom-args/tasty-inspector/i9970.scala @@ -46,7 +46,7 @@ object Test { // Inspector that performs the actual tests -class TestInspector() extends TastyInspector with +class TestInspector() extends TastyInspector: private var foundIOApp: Boolean = false private var foundSimple: Boolean = false diff --git a/tests/run-macros/BigFloat/BigFloatFromDigitsImpl_1.scala b/tests/run-macros/BigFloat/BigFloatFromDigitsImpl_1.scala index 324a583aead3..d77cf6334f2f 100644 --- a/tests/run-macros/BigFloat/BigFloatFromDigitsImpl_1.scala +++ b/tests/run-macros/BigFloat/BigFloatFromDigitsImpl_1.scala @@ -3,7 +3,7 @@ import language.experimental.genericNumberLiterals import scala.util.FromDigits import scala.quoted._ -object BigFloatFromDigitsImpl with +object BigFloatFromDigitsImpl: def apply(digits: Expr[String])(using Quotes): Expr[BigFloat] = digits.value match case Some(ds) => diff --git a/tests/run-macros/enum-nat-macro/Macros_2.scala b/tests/run-macros/enum-nat-macro/Macros_2.scala index d92878e1443f..19339ef403e8 100644 --- a/tests/run-macros/enum-nat-macro/Macros_2.scala +++ b/tests/run-macros/enum-nat-macro/Macros_2.scala @@ -4,7 +4,7 @@ import Nat._ inline def ZeroMacro: Zero.type = ${ Macros.natZero } transparent inline def toNatMacro(inline int: Int): Nat = ${ Macros.toNatImpl('int) } - object Macros with + object Macros: import quoted._ def toIntImpl(nat: Expr[Nat])(using Quotes): Expr[Int] = diff --git a/tests/run-macros/enum-nat-macro/Nat_1.scala b/tests/run-macros/enum-nat-macro/Nat_1.scala index 14733b4b57e2..fbb209698469 100644 --- a/tests/run-macros/enum-nat-macro/Nat_1.scala +++ b/tests/run-macros/enum-nat-macro/Nat_1.scala @@ -1,3 +1,3 @@ -enum Nat with +enum Nat: case Zero case Succ[N <: Nat](n: N) diff --git a/tests/run-macros/i10464/Person_1.scala b/tests/run-macros/i10464/Person_1.scala index 4c0845973a48..3973f018dd83 100644 --- a/tests/run-macros/i10464/Person_1.scala +++ b/tests/run-macros/i10464/Person_1.scala @@ -1,4 +1,4 @@ -trait Person with +trait Person: def name: String case class PersonA(name: String) extends Person diff --git a/tests/run-macros/i7716/Macro_1.scala b/tests/run-macros/i7716/Macro_1.scala index fe4b1c413c0a..01f4e5184a12 100644 --- a/tests/run-macros/i7716/Macro_1.scala +++ b/tests/run-macros/i7716/Macro_1.scala @@ -1,14 +1,14 @@ import scala.quoted._ -trait Foo with +trait Foo: def mcrImpl1(e: Expr[Any])(using ctx: Quotes): Expr[Any] = '{println(s"Hello ${$e}")} -object Foo extends Foo with +object Foo extends Foo: def mcrImpl2(e: Expr[Any])(using ctx: Quotes): Expr[Any] = '{println(s"Hello ${$e}")} -object Bar with +object Bar: import Foo._ inline def mcr1(e: => Any) = ${mcrImpl1('e)} diff --git a/tests/run-macros/i8530/Macro_1.scala b/tests/run-macros/i8530/Macro_1.scala index b15e2282961a..dc431c14ef14 100644 --- a/tests/run-macros/i8530/Macro_1.scala +++ b/tests/run-macros/i8530/Macro_1.scala @@ -1,6 +1,6 @@ import scala.quoted._ -object Succ with +object Succ: inline def unapply(n: Int): Option[Int] = ${ impl('n) } diff --git a/tests/run-macros/i9812b/Macro_1.scala b/tests/run-macros/i9812b/Macro_1.scala index 8b2e6f46cc52..ed1873195323 100644 --- a/tests/run-macros/i9812b/Macro_1.scala +++ b/tests/run-macros/i9812b/Macro_1.scala @@ -6,14 +6,14 @@ trait Liftable[T] { def toExpr(x: T): Quotes ?=> Expr[T] } -object Lift with +object Lift: def apply[T: Liftable](t: T)(using q: Quotes, ev: Liftable[T]): Expr[T] = ev.toExpr(t) sealed abstract class SomeEnum -object SomeEnum with +object SomeEnum: final val Foo = new SomeEnum {} final case class Bar[S <: SomeEnum](s: S) extends SomeEnum - object Bar with + object Bar: def apply[S <: SomeEnum](s: S): SomeEnum = new Bar(s) given LiftFoo: Liftable[Foo.type] with diff --git a/tests/run-macros/paramSymss/Test_2.scala b/tests/run-macros/paramSymss/Test_2.scala index 2ca016ddbcf6..4e2b53060c8b 100644 --- a/tests/run-macros/paramSymss/Test_2.scala +++ b/tests/run-macros/paramSymss/Test_2.scala @@ -16,5 +16,5 @@ object Test { println(showParamSyms(new Test(1, 2))) } -class Test[T](a: T) with +class Test[T](a: T): def this(a: Int, b: T) = this(b) diff --git a/tests/run-macros/refined-selectable-macro/Macro_1.scala b/tests/run-macros/refined-selectable-macro/Macro_1.scala index 05471dfd0adc..27dcbaa01082 100644 --- a/tests/run-macros/refined-selectable-macro/Macro_1.scala +++ b/tests/run-macros/refined-selectable-macro/Macro_1.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Macro { - trait Selectable extends scala.Selectable with + trait Selectable extends scala.Selectable: def selectDynamic(name: String): Any trait SelectableRecord extends Selectable { diff --git a/tests/run-macros/tasty-overload-secondargs/Macro_1.scala b/tests/run-macros/tasty-overload-secondargs/Macro_1.scala index 5a5b6137d5df..91c74945c92b 100644 --- a/tests/run-macros/tasty-overload-secondargs/Macro_1.scala +++ b/tests/run-macros/tasty-overload-secondargs/Macro_1.scala @@ -1,6 +1,6 @@ import scala.quoted._ -object X with +object X: def andThen[A,B](a:A)(f: A => B): B = println("totalFunction") @@ -11,7 +11,7 @@ object X with f.lift.apply(a) -object Macro with +object Macro: inline def mThen[A,B](inline x:A=>B):B = ${ mThenImpl[A,B,A=>B,B]('x) diff --git a/tests/run-macros/tasty-overload-secondargs/Test_2.scala b/tests/run-macros/tasty-overload-secondargs/Test_2.scala index 458cee275906..2584ed01346f 100644 --- a/tests/run-macros/tasty-overload-secondargs/Test_2.scala +++ b/tests/run-macros/tasty-overload-secondargs/Test_2.scala @@ -1,4 +1,4 @@ -object Test with +object Test: def main(args:Array[String]):Unit = val x1 = X.andThen(1){case x if (x%2 == 0) => x} diff --git a/tests/run-macros/tasty-tree-map/quoted_1.scala b/tests/run-macros/tasty-tree-map/quoted_1.scala index 4d7a101c5583..a4363f60b599 100644 --- a/tests/run-macros/tasty-tree-map/quoted_1.scala +++ b/tests/run-macros/tasty-tree-map/quoted_1.scala @@ -1,9 +1,9 @@ import scala.quoted._ -object Macros with +object Macros: implicit inline def identityMaped[T](x: => T): T = ${ MacrosImpl.impl('x) } -object MacrosImpl with +object MacrosImpl: def impl[T: Type](x: Expr[T])(using Quotes) : Expr[T] = { import quotes.reflect._ val identityMap = new TreeMap { } diff --git a/tests/run-staging/abstract-int-quote.scala b/tests/run-staging/abstract-int-quote.scala index f518d7372d77..c3070086104b 100644 --- a/tests/run-staging/abstract-int-quote.scala +++ b/tests/run-staging/abstract-int-quote.scala @@ -1,7 +1,7 @@ import scala.quoted._ import scala.quoted.staging._ -object Test with +object Test: given Compiler = Compiler.make(getClass.getClassLoader) diff --git a/tests/run-staging/i7897.scala b/tests/run-staging/i7897.scala index d7d0ea558846..2b0952971761 100644 --- a/tests/run-staging/i7897.scala +++ b/tests/run-staging/i7897.scala @@ -1,6 +1,6 @@ import scala.quoted._, staging._ -object Test with +object Test: given Compiler = Compiler.make(getClass.getClassLoader) val f: Array[Int] => Int = run { diff --git a/tests/run-staging/i8178.scala b/tests/run-staging/i8178.scala index bb2f95f7bdee..c0aeb545bad2 100644 --- a/tests/run-staging/i8178.scala +++ b/tests/run-staging/i8178.scala @@ -5,7 +5,7 @@ def foo(n: Int, t: Expr[Int])(using Quotes): Expr[Int] = if (n == 0) t else '{ val a = ${Expr(n)}; ${foo(n - 1, 'a)} + $t } -object Test with +object Test: def main(args: Array[String]) = { // make available the necessary toolbox for runtime code generation given Compiler = Compiler.make(getClass.getClassLoader) diff --git a/tests/run-staging/shonan-hmm-simple.scala b/tests/run-staging/shonan-hmm-simple.scala index 3cde9885bbe7..e17c998ed65e 100644 --- a/tests/run-staging/shonan-hmm-simple.scala +++ b/tests/run-staging/shonan-hmm-simple.scala @@ -1,7 +1,7 @@ import scala.quoted._ import scala.quoted.staging._ -trait Ring[T] with +trait Ring[T]: val zero: T val one: T val add: (x: T, y: T) => T @@ -9,7 +9,7 @@ trait Ring[T] with val mul: (x: T, y: T) => T end Ring -class RingInt extends Ring[Int] with +class RingInt extends Ring[Int]: val zero = 0 val one = 1 val add = (x, y) => x + y @@ -17,30 +17,30 @@ class RingInt extends Ring[Int] with val mul = (x, y) => x * y -class RingIntExpr(using Quotes) extends Ring[Expr[Int]] with +class RingIntExpr(using Quotes) extends Ring[Expr[Int]]: val zero = '{0} val one = '{1} val add = (x, y) => '{$x + $y} val sub = (x, y) => '{$x - $y} val mul = (x, y) => '{$x * $y} -class RingComplex[U](u: Ring[U]) extends Ring[Complex[U]] with +class RingComplex[U](u: Ring[U]) extends Ring[Complex[U]]: val zero = Complex(u.zero, u.zero) val one = Complex(u.one, u.zero) val add = (x, y) => Complex(u.add(x.re, y.re), u.add(x.im, y.im)) val sub = (x, y) => Complex(u.sub(x.re, y.re), u.sub(x.im, y.im)) val mul = (x, y) => Complex(u.sub(u.mul(x.re, y.re), u.mul(x.im, y.im)), u.add(u.mul(x.re, y.im), u.mul(x.im, y.re))) -sealed trait PV[T] with +sealed trait PV[T]: def expr(using ToExpr[T], Quotes): Expr[T] -case class Sta[T](x: T) extends PV[T] with +case class Sta[T](x: T) extends PV[T]: def expr(using ToExpr[T], Quotes): Expr[T] = Expr(x) -case class Dyn[T](x: Expr[T]) extends PV[T] with +case class Dyn[T](x: Expr[T]) extends PV[T]: def expr(using ToExpr[T], Quotes): Expr[T] = x -class RingPV[U: ToExpr](u: Ring[U], eu: Ring[Expr[U]])(using Quotes) extends Ring[PV[U]] with +class RingPV[U: ToExpr](u: Ring[U], eu: Ring[Expr[U]])(using Quotes) extends Ring[PV[U]]: val zero: PV[U] = Sta(u.zero) val one: PV[U] = Sta(u.one) val add = (x: PV[U], y: PV[U]) => (x, y) match @@ -62,28 +62,28 @@ class RingPV[U: ToExpr](u: Ring[U], eu: Ring[Expr[U]])(using Quotes) extends Rin case class Complex[T](re: T, im: T) -object Complex with - implicit def isToExpr[T: Type: ToExpr]: ToExpr[Complex[T]] = new ToExpr[Complex[T]] with +object Complex: + implicit def isToExpr[T: Type: ToExpr]: ToExpr[Complex[T]] = new ToExpr[Complex[T]]: def apply(comp: Complex[T])(using Quotes) = '{Complex(${Expr(comp.re)}, ${Expr(comp.im)})} -case class Vec[Idx, T](size: Idx, get: Idx => T) with +case class Vec[Idx, T](size: Idx, get: Idx => T): def map[U](f: T => U): Vec[Idx, U] = Vec(size, i => f(get(i))) def zipWith[U, V](other: Vec[Idx, U], f: (T, U) => V): Vec[Idx, V] = Vec(size, i => f(get(i), other.get(i))) -object Vec with +object Vec: def from[T](elems: T*): Vec[Int, T] = new Vec(elems.size, i => elems(i)) -trait VecOps[Idx, T] with +trait VecOps[Idx, T]: val reduce: ((T, T) => T, T, Vec[Idx, T]) => T -class StaticVecOps[T] extends VecOps[Int, T] with +class StaticVecOps[T] extends VecOps[Int, T]: val reduce: ((T, T) => T, T, Vec[Int, T]) => T = (plus, zero, vec) => var sum = zero for (i <- 0 until vec.size) sum = plus(sum, vec.get(i)) sum -class ExprVecOps[T: Type](using Quotes) extends VecOps[Expr[Int], Expr[T]] with +class ExprVecOps[T: Type](using Quotes) extends VecOps[Expr[Int], Expr[T]]: val reduce: ((Expr[T], Expr[T]) => Expr[T], Expr[T], Vec[Expr[Int], Expr[T]]) => Expr[T] = (plus, zero, vec) => '{ var sum = $zero var i = 0 @@ -93,10 +93,10 @@ class ExprVecOps[T: Type](using Quotes) extends VecOps[Expr[Int], Expr[T]] with sum } -class Blas1[Idx, T](r: Ring[T], ops: VecOps[Idx, T]) with +class Blas1[Idx, T](r: Ring[T], ops: VecOps[Idx, T]): def dot(v1: Vec[Idx, T], v2: Vec[Idx, T]): T = ops.reduce(r.add, r.zero, v1.zipWith(v2, r.mul)) -object Test with +object Test: given Compiler = Compiler.make(getClass.getClassLoader) def main(args: Array[String]): Unit = diff --git a/tests/run-staging/shonan-hmm/PV.scala b/tests/run-staging/shonan-hmm/PV.scala index bb81d2648b87..46e56b7d4ab7 100644 --- a/tests/run-staging/shonan-hmm/PV.scala +++ b/tests/run-staging/shonan-hmm/PV.scala @@ -7,7 +7,7 @@ case class Sta[T](x: T) extends PV[T] case class Dyn[T](x: Expr[T]) extends PV[T] -object Dyn with +object Dyn: def apply[T: ToExpr](x: T)(using Quotes): Dyn[T] = Dyn(Expr(x)) object Dyns { diff --git a/tests/run-with-compiler/intmaptest.scala b/tests/run-with-compiler/intmaptest.scala index c5ded14b5728..c12cb03e979d 100644 --- a/tests/run-with-compiler/intmaptest.scala +++ b/tests/run-with-compiler/intmaptest.scala @@ -1,12 +1,12 @@ -trait Generator[+T] with +trait Generator[+T]: self => def generate: T - def map[S](f: T => S) = new Generator[S] with + def map[S](f: T => S) = new Generator[S]: def generate: S = f(self.generate) - def flatMap[S](f: T => Generator[S]) = new Generator[S] with + def flatMap[S](f: T => Generator[S]) = new Generator[S]: def generate: S = f(self.generate).generate -object Generator with +object Generator: val NumLimit = 300 val Iterations = 10000 @@ -20,7 +20,7 @@ object Generator with def range(end: Int): Generator[Int] = integers.map(x => (x % end).abs) - enum Op with + enum Op: case Lookup, Update, Remove export Op._ diff --git a/tests/run-with-compiler/maptest.scala b/tests/run-with-compiler/maptest.scala index 1e1f5d0eb63f..9a4b42981d94 100644 --- a/tests/run-with-compiler/maptest.scala +++ b/tests/run-with-compiler/maptest.scala @@ -1,12 +1,12 @@ -trait Generator[+T] with +trait Generator[+T]: self => def generate: T - def map[S](f: T => S) = new Generator[S] with + def map[S](f: T => S) = new Generator[S]: def generate: S = f(self.generate) - def flatMap[S](f: T => Generator[S]) = new Generator[S] with + def flatMap[S](f: T => Generator[S]) = new Generator[S]: def generate: S = f(self.generate).generate -object Generator with +object Generator: val NumLimit = 300 val Iterations = 10000 @@ -20,7 +20,7 @@ object Generator with def range(end: Int): Generator[Int] = integers.map(x => (x % end).abs) - enum Op with + enum Op: case Lookup, Update, Remove export Op._ diff --git a/tests/run-with-compiler/settest.scala b/tests/run-with-compiler/settest.scala index c7d1e048ab9e..3a725990b840 100644 --- a/tests/run-with-compiler/settest.scala +++ b/tests/run-with-compiler/settest.scala @@ -1,12 +1,12 @@ -trait Generator[+T] with +trait Generator[+T]: self => def generate: T - def map[S](f: T => S) = new Generator[S] with + def map[S](f: T => S) = new Generator[S]: def generate: S = f(self.generate) - def flatMap[S](f: T => Generator[S]) = new Generator[S] with + def flatMap[S](f: T => Generator[S]) = new Generator[S]: def generate: S = f(self.generate).generate -object Generator with +object Generator: val NumLimit = 300 val Iterations = 10000 @@ -20,7 +20,7 @@ object Generator with def range(end: Int): Generator[Int] = integers.map(x => (x % end).abs) - enum Op with + enum Op: case Lookup, Update, Remove export Op._ diff --git a/tests/run/ConfManagement.scala b/tests/run/ConfManagement.scala index 12305a99728f..f73445b5af08 100644 --- a/tests/run/ConfManagement.scala +++ b/tests/run/ConfManagement.scala @@ -1,12 +1,12 @@ case class Person(name: String) case class Paper(title: String, authors: List[Person], body: String) -object ConfManagement with +object ConfManagement: opaque type Viewers = Set[Person] def viewers(using vs: Viewers) = vs type Viewed[T] = Viewers ?=> T - class Conference(ratings: (Paper, Int)*) with + class Conference(ratings: (Paper, Int)*): private val realScore = ratings.toMap def papers: List[Paper] = ratings.map(_._1).toList diff --git a/tests/run/LazyLists.scala b/tests/run/LazyLists.scala index 3d7ecc626af1..6cf8c8cf8e50 100644 --- a/tests/run/LazyLists.scala +++ b/tests/run/LazyLists.scala @@ -1,7 +1,7 @@ package xcollections: import annotation.unchecked.uncheckedVariance - abstract class LazyList[+T] with + abstract class LazyList[+T]: private var myHead: T = _ private var myTail: LazyList[T] = _ @@ -40,12 +40,12 @@ package xcollections: case xs: LazyList[T] @unchecked => xs case _ => LazyList.fromIterator(xs.iterator) - object LazyList with + object LazyList: val empty: LazyList[Nothing] = new: protected def force(): LazyList[Nothing] = this - object #:: with + object #:: : def unapply[T](xs: LazyList[T]): Option[(T, LazyList[T])] = if xs.isEmpty then None else Some((xs.head, xs.tail)) diff --git a/tests/run/Pouring.scala b/tests/run/Pouring.scala index e1db06c23d89..6f4611af8bfc 100644 --- a/tests/run/Pouring.scala +++ b/tests/run/Pouring.scala @@ -1,8 +1,8 @@ -class Pouring(capacity: Vector[Int]) with +class Pouring(capacity: Vector[Int]): type Glass = Int type Content = Vector[Int] - enum Move with + enum Move: def apply(content: Content): Content = this match case Empty(g) => content.updated(g, 0) case Fill(g) => content.updated(g, capacity(g)) @@ -23,7 +23,7 @@ class Pouring(capacity: Vector[Int]) with ++ (for g <- glasses yield Move.Fill(g)) ++ (for g1 <- glasses; g2 <- glasses if g1 != g2 yield Move.Pour(g1, g2)) - class Path(history: List[Move], val endContent: Content) with + class Path(history: List[Move], val endContent: Content): def extend(move: Move) = Path(move :: history, move(endContent)) override def toString = s"${history.reverse.mkString(" ")} --> $endContent" end Path diff --git a/tests/run/Signals.scala b/tests/run/Signals.scala index 33a5c929bb39..18a1947dcaf0 100644 --- a/tests/run/Signals.scala +++ b/tests/run/Signals.scala @@ -2,7 +2,7 @@ import annotation.unchecked._ package frp: - sealed class Signal[+T](expr: Signal.Caller ?=> T) with + sealed class Signal[+T](expr: Signal.Caller ?=> T): private var myExpr: Signal.Caller => T = _ private var myValue: T = _ private var observers: Set[Signal.Caller] = Set() @@ -26,19 +26,19 @@ package frp: observers = Set() obs.foreach(_.computeValue()) - object Signal with + object Signal: type Caller = Signal[?] given noCaller: Caller(???) with override def computeValue() = () end Signal - class Var[T](expr: Signal.Caller ?=> T) extends Signal[T](expr) with + class Var[T](expr: Signal.Caller ?=> T) extends Signal[T](expr): def update(expr: Signal.Caller ?=> T): Unit = changeTo(expr) end Var end frp import frp._ -class BankAccount with +class BankAccount: def balance: Signal[Int] = myBalance private var myBalance: Var[Int] = Var(0) diff --git a/tests/run/Signals1.scala b/tests/run/Signals1.scala index 178c1b276c0a..129965b4c2a5 100644 --- a/tests/run/Signals1.scala +++ b/tests/run/Signals1.scala @@ -2,12 +2,12 @@ import annotation.unchecked._ package frp: - trait Signal[+T] with + trait Signal[+T]: def apply()(using caller: Signal.Caller): T - object Signal with + object Signal: - abstract class AbstractSignal[+T] extends Signal[T] with + abstract class AbstractSignal[+T] extends Signal[T]: private var currentValue: T = _ private var observers: Set[Caller] = Set() @@ -29,11 +29,11 @@ package frp: end AbstractSignal def apply[T](expr: Caller ?=> T): Signal[T] = - new AbstractSignal[T] with + new AbstractSignal[T]: protected val eval = expr(using _) computeValue() - class Var[T](expr: Caller ?=> T) extends AbstractSignal[T] with + class Var[T](expr: Caller ?=> T) extends AbstractSignal[T]: protected var eval: Caller => T = expr(using _) computeValue() @@ -43,7 +43,7 @@ package frp: end Var opaque type Caller = AbstractSignal[?] - given noCaller: Caller = new AbstractSignal[Nothing] with + given noCaller: Caller = new AbstractSignal[Nothing]: override def eval = ??? override def computeValue() = () @@ -51,7 +51,7 @@ package frp: end frp import frp._ -class BankAccount with +class BankAccount: def balance: Signal[Int] = myBalance private val myBalance: Signal.Var[Int] = Signal.Var(0) diff --git a/tests/run/Typeable.scala b/tests/run/Typeable.scala index c2a76335c382..18bf9a4deb6a 100644 --- a/tests/run/Typeable.scala +++ b/tests/run/Typeable.scala @@ -16,15 +16,15 @@ * it's unclear whether this should expand to `C[T].unapply(x)`, (as it does now) * or to `C.unapply[T](x)` (which is what TypeLevel Scala 4 did, I believe) */ -trait Typeable[T] with +trait Typeable[T]: def cast(x: Any): Option[T] def describe: String override def toString = s"Typeable[$describe]" -object Typeable with +object Typeable: def apply[T: Typeable]: Typeable[T] = summon - class instanceOf[T: Typeable] with + class instanceOf[T: Typeable]: def unapply(x: Any): Option[T] = Typeable[T].cast(x) given int: Typeable[Int] with diff --git a/tests/run/abstract-givens.scala b/tests/run/abstract-givens.scala index 18f8a5aface1..6ff966411dde 100644 --- a/tests/run/abstract-givens.scala +++ b/tests/run/abstract-givens.scala @@ -1,9 +1,9 @@ -trait T with +trait T: given x: Int given y(using Int): String given z[T](using T): Seq[T] -object Test extends T, App with +object Test extends T, App: given x: Int = 22 override given y(using Int): String = summon[Int].toString given z[T](using T): Seq[T] with diff --git a/tests/run/context-functions.scala b/tests/run/context-functions.scala index 64da62d3de88..e71f0de10378 100644 --- a/tests/run/context-functions.scala +++ b/tests/run/context-functions.scala @@ -1,4 +1,4 @@ -trait A with +trait A: type Ctx[T] type Mega[T] @@ -14,7 +14,7 @@ trait A with def trans(x: Ctx[Int]): Ctx[Int] = x end A -object m extends A with +object m extends A: type Ctx[T] = String ?=> T type Mega[T] = (Int, Int, Int, Int, Int, @@ -36,7 +36,7 @@ object m extends A with def mega: Mega[Int] = summon[String].length end m -trait B with +trait B: type Ctx[T] @@ -45,7 +45,7 @@ trait B with def id[T](x: T): T = drop(wrap(x)) end B -object n extends B with +object n extends B: type Ctx[T] = String ?=> Int ?=> T def wrap[T](x: T): Ctx[T] = x diff --git a/tests/run/decorators/DocComment.scala b/tests/run/decorators/DocComment.scala index 5b1402fdd588..85b30fbce393 100644 --- a/tests/run/decorators/DocComment.scala +++ b/tests/run/decorators/DocComment.scala @@ -5,7 +5,7 @@ * `body` what comes before the first tagged line */ case class DocComment(body: String, tags: Map[String, List[String]]) -object DocComment with +object DocComment: def fromString(str: String): DocComment = val lines = str.linesIterator.toList def tagged(line: String): Option[(String, String)] = diff --git a/tests/run/decorators/EntryPoint.scala b/tests/run/decorators/EntryPoint.scala index 5f3c341ad5c2..f87519fabee0 100644 --- a/tests/run/decorators/EntryPoint.scala +++ b/tests/run/decorators/EntryPoint.scala @@ -1,7 +1,7 @@ import collection.mutable /** A framework for defining stackable entry point wrappers */ -object EntryPoint with +object EntryPoint: /** A base trait for wrappers of entry points. * Sub-traits: Annotation#Wrapper @@ -26,14 +26,14 @@ object EntryPoint with * * The wrapper class has this outline: * - * object with + * object : * @WrapperAnnotation def (args: ) = * ... * * Here `` and `` are obtained from an * inline call to the `wrapperName` method. */ - trait Annotation extends annotation.StaticAnnotation with + trait Annotation extends annotation.StaticAnnotation: /** The class used for argument parsing. E.g. `scala.util.FromString`, if * arguments are strings, but it could be something else. @@ -56,7 +56,7 @@ object EntryPoint with def wrapper(entryPointName: String, docComment: String): Wrapper /** Base class for descriptions of an entry point wrappers */ - abstract class Wrapper extends EntryPoint.Wrapper with + abstract class Wrapper extends EntryPoint.Wrapper: /** The type of the wrapper argument. E.g., for Java main methods: `Array[String]` */ type Argument @@ -80,7 +80,7 @@ object EntryPoint with def call(arg: Argument): Call /** A class representing a wrapper call */ - abstract class Call with + abstract class Call: /** The getter for the next argument of type `T` */ def nextArgGetter[T](argName: String, fromString: ArgumentParser[T], defaultValue: Option[T] = None): () => T @@ -124,7 +124,7 @@ object EntryPoint with * created from @logged, @transactional, and @main, respectively. * - `x` is the argument of the outer $logged$wrapper. */ - trait Adapter extends annotation.StaticAnnotation with + trait Adapter extends annotation.StaticAnnotation: /** Creates a new wrapper around `wrapped` */ def wrapper(wrapped: EntryPoint.Wrapper): Wrapper @@ -169,7 +169,7 @@ object EntryPoint with * keep the `adapt` type contract implicit (types are still checked when adapts * are generated, of course). */ - abstract class Wrapper extends EntryPoint.Wrapper with + abstract class Wrapper extends EntryPoint.Wrapper: /** The wrapper that this wrapped in turn by this wrapper */ val wrapped: EntryPoint.Wrapper diff --git a/tests/run/decorators/Test.scala b/tests/run/decorators/Test.scala index 6e840ab26bd0..1d821d2109d2 100644 --- a/tests/run/decorators/Test.scala +++ b/tests/run/decorators/Test.scala @@ -1,4 +1,4 @@ -object Test with +object Test: def main(args: Array[String]) = def testAdd(args: String) = println(s"> java add $args") diff --git a/tests/run/decorators/main.scala b/tests/run/decorators/main.scala index feb6d7a6567e..a6fecc00b6e6 100644 --- a/tests/run/decorators/main.scala +++ b/tests/run/decorators/main.scala @@ -3,7 +3,7 @@ import collection.mutable /** A sample @main entry point annotation. * Generates a main function. */ -class main extends EntryPoint.Annotation with +class main extends EntryPoint.Annotation: type ArgumentParser[T] = util.CommandLineParser.FromString[T] type EntryPointResult = Unit @@ -13,11 +13,11 @@ class main extends EntryPoint.Annotation with def wrapper(name: String, doc: String): MainWrapper = new MainWrapper(name, doc) - class MainWrapper(val entryPointName: String, val docComment: String) extends Wrapper with + class MainWrapper(val entryPointName: String, val docComment: String) extends Wrapper: type Argument = Array[String] type Result = Unit - def call(args: Array[String]) = new Call with + def call(args: Array[String]) = new Call: /** A buffer of demanded argument names, plus * "?" if it has a default diff --git a/tests/run/decorators/sample-adapters.scala b/tests/run/decorators/sample-adapters.scala index 5cb868949e17..77622261d16e 100644 --- a/tests/run/decorators/sample-adapters.scala +++ b/tests/run/decorators/sample-adapters.scala @@ -1,10 +1,10 @@ // Sample adapters: -class logged extends EntryPoint.Adapter with +class logged extends EntryPoint.Adapter: def wrapper(wrapped: EntryPoint.Wrapper): LoggedWrapper = LoggedWrapper(wrapped) - class LoggedWrapper(val wrapped: EntryPoint.Wrapper) extends Wrapper with + class LoggedWrapper(val wrapped: EntryPoint.Wrapper) extends Wrapper: def adapt[A, R](op: A => R)(args: A): R = val argsString: String = args match case args: Array[_] => args.mkString(", ") @@ -17,18 +17,18 @@ class logged extends EntryPoint.Adapter with end LoggedWrapper end logged -class split extends EntryPoint.Adapter with +class split extends EntryPoint.Adapter: def wrapper(wrapped: EntryPoint.Wrapper): SplitWrapper = SplitWrapper(wrapped) - class SplitWrapper(val wrapped: EntryPoint.Wrapper) extends Wrapper with + class SplitWrapper(val wrapped: EntryPoint.Wrapper) extends Wrapper: def adapt[R](op: Array[String] => R)(args: String): R = op(args.split(" ")) end split -class join extends EntryPoint.Adapter with +class join extends EntryPoint.Adapter: def wrapper(wrapped: EntryPoint.Wrapper): JoinWrapper = JoinWrapper(wrapped) - class JoinWrapper(val wrapped: EntryPoint.Wrapper) extends Wrapper with + class JoinWrapper(val wrapped: EntryPoint.Wrapper) extends Wrapper: def adapt[R](op: String => R)(args: Array[String]): R = op(args.mkString(" ")) end join diff --git a/tests/run/decorators/sample-program.scala b/tests/run/decorators/sample-program.scala index 7447d40981e6..1f58f4cd3260 100644 --- a/tests/run/decorators/sample-program.scala +++ b/tests/run/decorators/sample-program.scala @@ -1,4 +1,4 @@ -object myProgram with +object myProgram: /** Adds two numbers * @param num the first number @@ -15,7 +15,7 @@ end myProgram // Compiler generated code: -object add with +object add: private val $main = new main() private val $main$wrapper = $main.wrapper( "MyProgram.add", @@ -29,7 +29,7 @@ object add with cll.run(myProgram.add(arg1(), arg2())) end add -object addAll with +object addAll: private val $main = new main() private val $split = new split() private val $logged = new logged() diff --git a/tests/run/defunctionalized.scala b/tests/run/defunctionalized.scala index c48b1bb6ad9a..aa236b8d22fb 100644 --- a/tests/run/defunctionalized.scala +++ b/tests/run/defunctionalized.scala @@ -1,4 +1,4 @@ -enum Filter with +enum Filter: case IsOdd case IsPrime case LessThan(bound: Int) diff --git a/tests/run/enum-custom-toString.scala b/tests/run/enum-custom-toString.scala index 9ef9ff044679..7432bde87ff9 100644 --- a/tests/run/enum-custom-toString.scala +++ b/tests/run/enum-custom-toString.scala @@ -1,23 +1,23 @@ -enum ES with +enum ES: case A override def toString: String = "overridden" -enum EJ extends java.lang.Enum[EJ] with +enum EJ extends java.lang.Enum[EJ]: case B override def toString: String = "overridden" -trait Mixin extends reflect.Enum with +trait Mixin extends reflect.Enum: override def productPrefix: String = "noprefix" override def toString: String = "overridden" -enum EM extends Mixin with +enum EM extends Mixin: case C -enum ET[T] extends java.lang.Enum[ET[_]] with +enum ET[T] extends java.lang.Enum[ET[_]]: case D extends ET[Unit] override def toString: String = "overridden" -enum EZ with +enum EZ: case E(arg: Int) override def toString: String = "overridden" @@ -25,20 +25,20 @@ enum EC: // control case case F case G(arg: Int) -enum EO with +enum EO: case H case I(arg: Int) override def productPrefix: String = "noprefix" override def toString: String = "overridden" end EO -enum EQ with +enum EQ: case J extends EQ with Mixin case K(arg: Int) extends EQ with Mixin abstract class Tag[T] extends reflect.Enum -object Tag with - private final class IntTagImpl extends Tag[Int] with runtime.EnumValue with +object Tag: + private final class IntTagImpl extends Tag[Int] with runtime.EnumValue: def ordinal = 0 override def hashCode = 123 final val IntTag: Tag[Int] = IntTagImpl() diff --git a/tests/run/enum-nat.scala b/tests/run/enum-nat.scala index 25149c8d2b48..47bddcc665cd 100644 --- a/tests/run/enum-nat.scala +++ b/tests/run/enum-nat.scala @@ -1,11 +1,11 @@ import Nat._ import compiletime._ -enum Nat with +enum Nat: case Zero case Succ[N <: Nat.Refract](n: N) -object Nat with +object Nat: type Refract = Zero.type | Succ[_] inline def toIntTypeLevel[N <: Nat]: Int = inline erasedValue[N] match diff --git a/tests/run/enum-ordinal-java/Lib.scala b/tests/run/enum-ordinal-java/Lib.scala index 69fc8190e02e..75b9003e5553 100644 --- a/tests/run/enum-ordinal-java/Lib.scala +++ b/tests/run/enum-ordinal-java/Lib.scala @@ -1,5 +1,5 @@ -object Lib1 with +object Lib1: trait MyJavaEnum[E <: java.lang.Enum[E]] extends java.lang.Enum[E] -object Lib2 with +object Lib2: type JavaEnumAlias[E <: java.lang.Enum[E]] = java.lang.Enum[E] diff --git a/tests/run/enum-ordinal-java/Test.scala b/tests/run/enum-ordinal-java/Test.scala index 83625d581082..082ea85f7044 100644 --- a/tests/run/enum-ordinal-java/Test.scala +++ b/tests/run/enum-ordinal-java/Test.scala @@ -1,7 +1,7 @@ -enum Color1 extends Lib1.MyJavaEnum[Color1] with +enum Color1 extends Lib1.MyJavaEnum[Color1]: case Red, Green, Blue -enum Color2 extends Lib2.JavaEnumAlias[Color2] with +enum Color2 extends Lib2.JavaEnumAlias[Color2]: case Red, Green, Blue @main def Test = diff --git a/tests/run/enum-values-order.scala b/tests/run/enum-values-order.scala index 3721728fc2a0..400cdbc8aac5 100644 --- a/tests/run/enum-values-order.scala +++ b/tests/run/enum-values-order.scala @@ -5,9 +5,9 @@ enum LatinAlphabet2 extends java.lang.Enum[LatinAlphabet2] { case A, B, C, D, E, enum LatinAlphabet3[+T] extends java.lang.Enum[LatinAlphabet3[_]] { case A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z } -object Color with +object Color: trait Pretty -enum Color extends java.lang.Enum[Color] with +enum Color extends java.lang.Enum[Color]: case Red, Green, Blue case Aqua extends Color with Color.Pretty case Grey, Black, White diff --git a/tests/run/enum-values.scala b/tests/run/enum-values.scala index f858d47a6792..a7b838ba73cd 100644 --- a/tests/run/enum-values.scala +++ b/tests/run/enum-values.scala @@ -1,31 +1,31 @@ import reflect.Selectable.reflectiveSelectable import deriving.Mirror -enum Color with +enum Color: case Red, Green, Blue -enum Suits extends java.lang.Enum[Suits] with +enum Suits extends java.lang.Enum[Suits]: case Clubs, Spades, Diamonds, Hearts -enum Tag[T] with +enum Tag[T]: case Int extends Tag[Int] case OfClass[T]()(using val tag: reflect.ClassTag[T]) extends Tag[T] // mix order of class and value case String extends Tag[String] -enum Expr[-T >: Null] with +enum Expr[-T >: Null]: case EmptyTree extends Expr[Null] case AnyTree -enum ListLike[+T] with +enum ListLike[+T]: case Cons[T](head: T, tail: ListLike[T]) extends ListLike[T] case EmptyListLike -enum TypeCtorsK[F[_]] with +enum TypeCtorsK[F[_]]: case List extends TypeCtorsK[List] case Const[T]() extends TypeCtorsK[[U] =>> T] // mix order of class and value case Option extends TypeCtorsK[Option] -enum MixedParams[F[_], G[X,Y] <: collection.Map[X,Y], T] with +enum MixedParams[F[_], G[X,Y] <: collection.Map[X,Y], T]: case Foo extends MixedParams[List, collection.mutable.LinkedHashMap, Unit] enum ClassOnly: // this should still generate the `ordinal` and `fromOrdinal` companion methods diff --git a/tests/run/enums-precise.scala b/tests/run/enums-precise.scala index 59867e9f6100..1ae98ca6664f 100644 --- a/tests/run/enums-precise.scala +++ b/tests/run/enums-precise.scala @@ -1,8 +1,8 @@ -enum NonEmptyList[+T] with +enum NonEmptyList[+T]: case Many[+U](head: U, tail: NonEmptyList[U]) extends NonEmptyList[U] case One [+U](value: U) extends NonEmptyList[U] -enum Ast with +enum Ast: case Binding(name: String, tpe: String) case Lambda(args: NonEmptyList[Binding], rhs: Ast) // reference to another case of the enum case Ident(name: String) diff --git a/tests/run/enums-serialization-compat.scala b/tests/run/enums-serialization-compat.scala index dfa8a7d06ee1..940e726c05a0 100644 --- a/tests/run/enums-serialization-compat.scala +++ b/tests/run/enums-serialization-compat.scala @@ -1,22 +1,22 @@ import java.io._ import scala.util.Using -enum JColor extends java.lang.Enum[JColor] with +enum JColor extends java.lang.Enum[JColor]: case Red // java enum has magic JVM support -enum SColor with +enum SColor: case Green // simple case last -enum SColorTagged[T] with +enum SColorTagged[T]: case Blue extends SColorTagged[Unit] case Rgb(r: Byte, g: Byte, b: Byte) extends SColorTagged[(Byte, Byte, Byte)] // mixing pattern kinds case Indigo extends SColorTagged[Unit] case Cmyk(c: Byte, m: Byte, y: Byte, k: Byte) extends SColorTagged[(Byte, Byte, Byte, Byte)] // class case last -enum Nucleobase with +enum Nucleobase: case A,C,G,T // patdef last -enum MyClassTag[T](wrapped: Class[?]) with +enum MyClassTag[T](wrapped: Class[?]): case IntTag extends MyClassTag[Int](classOf[Int]) case UnitTag extends MyClassTag[Unit](classOf[Unit]) // value case last diff --git a/tests/run/erased-inline-vals.scala b/tests/run/erased-inline-vals.scala index b74d2bfe2151..57e2901a62ea 100644 --- a/tests/run/erased-inline-vals.scala +++ b/tests/run/erased-inline-vals.scala @@ -1,17 +1,17 @@ -abstract class A with +abstract class A: def x: Int val y: Int -class B extends A with +class B extends A: inline def x: Int = 1 inline val y = 2 -class C extends A with +class C extends A: final val x: Int = 3 final val y = 4 -class D with +class D: inline def x: Int = 5 inline val y = 6 diff --git a/tests/run/exports.scala b/tests/run/exports.scala index ee409f95fbc1..f68312ca54e2 100644 --- a/tests/run/exports.scala +++ b/tests/run/exports.scala @@ -48,8 +48,8 @@ final class Foo { export foo._ // nothing is exported } -class A with +class A: val x: Int = 1 -class B(a: A) with +class B(a: A): export a.x object B extends B(A()) \ No newline at end of file diff --git a/tests/run/extension-override.scala b/tests/run/extension-override.scala index e77faa18b199..00246f611391 100644 --- a/tests/run/extension-override.scala +++ b/tests/run/extension-override.scala @@ -1,8 +1,8 @@ -class A with +class A: extension (s: String) def len: Int = s.length -object B extends A with +object B extends A: extension (s: String) override def len: Int = s.length + 1 diff --git a/tests/run/fragables-extension.scala b/tests/run/fragables-extension.scala index 071cc4fd78d1..417a612a3f04 100644 --- a/tests/run/fragables-extension.scala +++ b/tests/run/fragables-extension.scala @@ -3,7 +3,7 @@ trait Frag case class IntFrag(x: Int) extends Frag case class StringFrag(x: String) extends Frag -trait Fragable[T] with +trait Fragable[T]: extension (x: T) def toFrags: List[Frag] diff --git a/tests/run/given-eta.scala b/tests/run/given-eta.scala index 07b088e0188e..1eaf6fd16c49 100644 --- a/tests/run/given-eta.scala +++ b/tests/run/given-eta.scala @@ -1,6 +1,6 @@ class C(val x: Int) -trait D with +trait D: type T def trans(other: T): T diff --git a/tests/run/given-var.scala b/tests/run/given-var.scala index 13fc9c9f8755..fa4ee45e77e6 100644 --- a/tests/run/given-var.scala +++ b/tests/run/given-var.scala @@ -1,5 +1,5 @@ // Demonstrates that monomorphic givens are cached -object a with +object a: private var x = 1 given Int = x def init(x: Int) = this.x = x diff --git a/tests/run/i10082.scala b/tests/run/i10082.scala index b3b24f1d7a6f..299083da3567 100644 --- a/tests/run/i10082.scala +++ b/tests/run/i10082.scala @@ -1,4 +1,4 @@ -object Kotlin with +object Kotlin: class Ctx[T](val x: T) extends AnyVal def fun[T, U](fn: Ctx[T] ?=> U): T => U = (x: T) => fn(using Ctx(x)) diff --git a/tests/run/i10857.scala b/tests/run/i10857.scala index 9af4f88e19a6..c8b28d04651e 100644 --- a/tests/run/i10857.scala +++ b/tests/run/i10857.scala @@ -1,6 +1,6 @@ -object Module with +object Module: - enum Foo with + enum Foo: case Value case Parameterised(i: Int) diff --git a/tests/run/i10884/Test_2.scala b/tests/run/i10884/Test_2.scala index c336613bc414..72e7fafa9674 100644 --- a/tests/run/i10884/Test_2.scala +++ b/tests/run/i10884/Test_2.scala @@ -1,4 +1,4 @@ -object Exporter with +object Exporter: export JavaExporter_1._ import Exporter._ diff --git a/tests/run/i10905.scala b/tests/run/i10905.scala index af8baafc9099..2637d69cc8a2 100644 --- a/tests/run/i10905.scala +++ b/tests/run/i10905.scala @@ -1,5 +1,5 @@ class C(val x: Int) extends TypeHelpers -abstract class TypeHelpers with +abstract class TypeHelpers: self: C => def f = x @main def Test = diff --git a/tests/run/i7359.scala b/tests/run/i7359.scala index b10967e06479..c01b9d05f274 100644 --- a/tests/run/i7359.scala +++ b/tests/run/i7359.scala @@ -1,34 +1,34 @@ -trait ObjectInterface with +trait ObjectInterface: def equals(obj: Any): Boolean def hashCode(): Int def toString(): String -trait SAMPlainWithExtends extends ObjectInterface with +trait SAMPlainWithExtends extends ObjectInterface: def first(): String -trait SAMCovariantOutExtends[+O] extends ObjectInterface with +trait SAMCovariantOutExtends[+O] extends ObjectInterface: def first(): O -trait SAMContravariantInExtends[-I] extends ObjectInterface with +trait SAMContravariantInExtends[-I] extends ObjectInterface: def first(in: I): Unit -trait SAMInvariantExtends[T] extends ObjectInterface with +trait SAMInvariantExtends[T] extends ObjectInterface: def first(in: T): T -trait SAMInOutExtends[-I, +O] extends ObjectInterface with +trait SAMInOutExtends[-I, +O] extends ObjectInterface: def first(in: I): O type CustomString = String type CustomBoolean = Boolean type CustomInt = Int -trait SAMWithCustomAliases with +trait SAMWithCustomAliases: def first(): String def equals(obj: Any): CustomBoolean def hashCode(): CustomInt def toString(): CustomString -object Test with +object Test: def main(args: Array[String]): Unit = val samPlainWithExtends : SAMPlainWithExtends = () => "o" diff --git a/tests/run/i7788.scala b/tests/run/i7788.scala index 83341f80a4c2..99d16ba1521c 100644 --- a/tests/run/i7788.scala +++ b/tests/run/i7788.scala @@ -1,4 +1,4 @@ -trait Show[-A] with +trait Show[-A]: def show(a:A): String given Show[String] = x => x diff --git a/tests/run/i8396.scala b/tests/run/i8396.scala index 602f425d29c0..3e44e3898dc5 100644 --- a/tests/run/i8396.scala +++ b/tests/run/i8396.scala @@ -1,7 +1,7 @@ -trait Show[A] with +trait Show[A]: def show(a: A): String = a.toString -object Prefix with +object Prefix: type AbstractType type UpperBoundedType <: String type FullyBoundedType >: String <: String diff --git a/tests/run/i8530-b.scala b/tests/run/i8530-b.scala index ff3a8d76943e..80171bc4d178 100644 --- a/tests/run/i8530-b.scala +++ b/tests/run/i8530-b.scala @@ -1,6 +1,6 @@ import scala.compiletime.erasedValue -class MyRegex[Pattern <: String & Singleton/*Literal constant*/] with +class MyRegex[Pattern <: String & Singleton/*Literal constant*/]: inline def unapplySeq(s: CharSequence): Option[List[String]] = inline erasedValue[Pattern] match case "foo" => if s == "foo" then Some(Nil) else None diff --git a/tests/run/i8530.scala b/tests/run/i8530.scala index 66a93344e433..bbbc52587ee0 100644 --- a/tests/run/i8530.scala +++ b/tests/run/i8530.scala @@ -1,16 +1,16 @@ -object MyBoooleanUnapply with +object MyBoooleanUnapply: inline def unapply(x: Int): Boolean = true -object MyOptionUnapply with +object MyOptionUnapply: inline def unapply(x: Int): Option[Long] = Some(x) -object MyPolyUnapply with +object MyPolyUnapply: inline def unapply[T](x: T): Option[T] = Some(x) -object MySeqUnapply with +object MySeqUnapply: inline def unapplySeq(x: Int): Seq[Int] = Seq(x, x + 1) -object MyWhiteboxUnapply with +object MyWhiteboxUnapply: transparent inline def unapply(x: Int): Option[Any] = Some(x) diff --git a/tests/run/i8931.scala b/tests/run/i8931.scala index ab1ed7f54a23..555d15d0121d 100644 --- a/tests/run/i8931.scala +++ b/tests/run/i8931.scala @@ -1,4 +1,4 @@ -object test1 with +object test1: trait Trait @@ -18,7 +18,7 @@ object test1 with } } -object test2 with +object test2: trait Trait @@ -38,16 +38,16 @@ object test2 with } } -object test3 with +object test3: trait Trait - trait Managed[T] with + trait Managed[T]: def flatMap[U](f: T => Managed[U]) = - class C with + class C: def make() = - class D with + class D: def bar(): T = ??? val t: T = ??? val u = diff --git a/tests/run/i9011.scala b/tests/run/i9011.scala index 495bd924fad0..c75871a865bb 100644 --- a/tests/run/i9011.scala +++ b/tests/run/i9011.scala @@ -1,4 +1,4 @@ -enum Opt[+T] derives Eq with +enum Opt[+T] derives Eq: case Sm[T](t: T) extends Opt[T] case Nn diff --git a/tests/run/i9068.scala b/tests/run/i9068.scala index b0dedaad21de..c66dc72dbab1 100644 --- a/tests/run/i9068.scala +++ b/tests/run/i9068.scala @@ -1,4 +1,4 @@ -case class MyClass(v1: Int, v2: Int, v3: Int, v4: Int) extends Product3[Int, Int, Int] with +case class MyClass(v1: Int, v2: Int, v3: Int, v4: Int) extends Product3[Int, Int, Int]: val _1: Int = v2 def _2: Int = v3 var _3: Int = v4 diff --git a/tests/run/i9155.scala b/tests/run/i9155.scala index d5ae94b24c2d..2f5bf086c8eb 100644 --- a/tests/run/i9155.scala +++ b/tests/run/i9155.scala @@ -1,7 +1,7 @@ -object Foo with +object Foo: @scala.annotation.targetName("w") def \/\/ = "W" -object Bar with +object Bar: export Foo._ @main def Test = diff --git a/tests/run/i9530.scala b/tests/run/i9530.scala index 0db77c1cadd3..e0262764039f 100644 --- a/tests/run/i9530.scala +++ b/tests/run/i9530.scala @@ -1,4 +1,4 @@ -trait Scope with +trait Scope: type Expr type Value def expr(x: String): Expr diff --git a/tests/run/i9928.scala b/tests/run/i9928.scala index 3dc08a8553db..3a3f818b17d3 100644 --- a/tests/run/i9928.scala +++ b/tests/run/i9928.scala @@ -1,17 +1,17 @@ -trait Magic[F] with +trait Magic[F]: extension (x: Int) def read: F -trait LowPrio with +trait LowPrio: given Magic[String] with extension(x: Int) def read: String = println("In string") s"$x" -object test1 with +object test1: object Magic extends LowPrio opaque type Foo = String - object Foo extends LowPrio with + object Foo extends LowPrio: import Magic.given def apply(s: String): Foo = s @@ -23,15 +23,15 @@ object test1 with def test: Unit = (3.read: Foo) -object test2 with - object Magic extends LowPrio with +object test2: + object Magic extends LowPrio: given Magic[Foo] with extension (x: Int) def read: Foo = println("In foo") Foo(s"$x") opaque type Foo = String - object Foo extends LowPrio with + object Foo extends LowPrio: import Magic.given def apply(s: String): Foo = s diff --git a/tests/run/ift-return.scala b/tests/run/ift-return.scala index f67028b712b7..021c73173051 100644 --- a/tests/run/ift-return.scala +++ b/tests/run/ift-return.scala @@ -1,7 +1,7 @@ -trait A with +trait A: val x: Int -trait Ctx with +trait Ctx: type T val x: T val y: T diff --git a/tests/run/inline-override.scala b/tests/run/inline-override.scala index 83a6a61424e7..a128002fc4ba 100644 --- a/tests/run/inline-override.scala +++ b/tests/run/inline-override.scala @@ -1,12 +1,12 @@ import annotation.targetName -abstract class A with +abstract class A: def f(x: Int) = s"dynamic $x" def h(x: Int): String @targetName("h2") def h1(x: Int): String inline def i(x: Int): String -class B extends A with +class B extends A: inline override def f(x: Int) = g(x) inline def g(x: Int) = s"inline $x" inline def h(x: Int) = g(x) diff --git a/tests/run/instances.scala b/tests/run/instances.scala index bbb6fc22312a..128ea0700e02 100644 --- a/tests/run/instances.scala +++ b/tests/run/instances.scala @@ -40,10 +40,10 @@ object Test extends App { assert(List(names, List("!")).flattened == names :+ "!") assert(Nil.flattened == Nil) - trait SemiGroup[T] with + trait SemiGroup[T]: extension (x: T) def combine(y: T): T - trait Monoid[T] extends SemiGroup[T] with + trait Monoid[T] extends SemiGroup[T]: def unit: T given StringMonoid: Monoid[String] with @@ -56,7 +56,7 @@ object Test extends App { println(sum(names)) - trait Ord[T] with + trait Ord[T]: extension (x: T) def compareTo(y: T): Int extension (x: T) def < (y: T) = x.compareTo(y) < 0 extension (x: T) def > (y: T) = x.compareTo(y) > 0 @@ -88,11 +88,11 @@ object Test extends App { println(max(List(1, 2, 3), List(2))) - trait Functor[F[_]] with + trait Functor[F[_]]: extension [A](x: F[A]) def map[B](f: A => B): F[B] end Functor - trait Monad[F[_]] extends Functor[F] with + trait Monad[F[_]] extends Functor[F]: extension [A](x: F[A]) def flatMap[B](f: A => F[B]): F[B] extension [A](x: F[A]) def map[B](f: A => B) = x.flatMap(f `andThen` pure) diff --git a/tests/run/lazy-impl.scala b/tests/run/lazy-impl.scala index ca7ed5852c2b..a941dc89100a 100644 --- a/tests/run/lazy-impl.scala +++ b/tests/run/lazy-impl.scala @@ -46,7 +46,7 @@ * The code makes use of the following runtime class: - class Waiting with + class Waiting: private var done = false def release(): Unit = synchronized: done = true diff --git a/tests/run/option-extract.scala b/tests/run/option-extract.scala index 588ab1c445d0..7b87ad28bc68 100644 --- a/tests/run/option-extract.scala +++ b/tests/run/option-extract.scala @@ -1,5 +1,5 @@ -enum Option[+A] with +enum Option[+A]: case Some(x: A) case None diff --git a/tests/run/outer-accessors.scala b/tests/run/outer-accessors.scala index b8378a8337cd..47d7a5b1849d 100644 --- a/tests/run/outer-accessors.scala +++ b/tests/run/outer-accessors.scala @@ -1,15 +1,15 @@ -class A with +class A: val a = 2 - class B with + class B: val b = 3 - trait T with + trait T: def t = a + b val bb = B() - class C extends bb.T with + class C extends bb.T: def result = a + t @main def Test = diff --git a/tests/run/quoted-sematics-1.scala b/tests/run/quoted-sematics-1.scala index 6f77a0ec2903..ed2d05224d73 100644 --- a/tests/run/quoted-sematics-1.scala +++ b/tests/run/quoted-sematics-1.scala @@ -25,7 +25,7 @@ object Name { } -enum Term with +enum Term: case Nat(n: Int) case Ref(name: Name) case Lambda(name: Name, tpe: Type, body: Term) @@ -37,7 +37,7 @@ enum Term with case Fix(term: Term) -enum Pattern with +enum Pattern: case PNat(n: Int) case PRef(name: Name) case PApp(fun: Pattern, arg: Pattern) @@ -46,7 +46,7 @@ enum Pattern with case PFun(name: Name) -enum Type with +enum Type: case NatType case LambdaType(arg: Type, res: Type) case BoxType(inner: Type) diff --git a/tests/run/selectable-new.scala b/tests/run/selectable-new.scala index d8cf18d228ca..e460ca631b56 100644 --- a/tests/run/selectable-new.scala +++ b/tests/run/selectable-new.scala @@ -1,10 +1,10 @@ @main def Test = val x = - class C extends reflect.Selectable with + class C extends reflect.Selectable: def name: String = "hello" new C - val y = new reflect.Selectable with + val y = new reflect.Selectable: def name: String = "hello" assert(x.name == "hello") diff --git a/tests/run/singleton-ops-flags.scala b/tests/run/singleton-ops-flags.scala index 2f316ab56a92..8e2cda6a38c7 100644 --- a/tests/run/singleton-ops-flags.scala +++ b/tests/run/singleton-ops-flags.scala @@ -3,7 +3,7 @@ package example { import compiletime.S import compiletime.ops.int.<< - object TastyFlags with + object TastyFlags: final val EmptyFlags = baseFlags final val Erased = EmptyFlags.next @@ -40,7 +40,7 @@ package example { case Open => "Open" }) mkString(" | ") - object opaques with + object opaques: opaque type FlagSet = Int opaque type EmptyFlagSet <: FlagSet = 0 diff --git a/tests/run/structural-contextual.scala b/tests/run/structural-contextual.scala index b12f6fee348b..e1d0890b73cd 100644 --- a/tests/run/structural-contextual.scala +++ b/tests/run/structural-contextual.scala @@ -1,7 +1,7 @@ -trait Resolver with +trait Resolver: def resolve(label: String): Any -class ResolvingSelectable extends Selectable with +class ResolvingSelectable extends Selectable: def selectDynamic(label: String)(using r: Resolver): Any = r.resolve(label) def applyDynamic(label: String)(args: Any*)(using r: Resolver): Any = diff --git a/tests/run/targetName.scala b/tests/run/targetName.scala index 721c614c37a9..7774922c7b12 100644 --- a/tests/run/targetName.scala +++ b/tests/run/targetName.scala @@ -1,23 +1,23 @@ import annotation.targetName -object A with +object A: def f(x: => String): Int = x.length @targetName("f2") def f(x: => Int): Int = x import A._ -trait T with +trait T: def f(x: => String): Int @targetName("f2") def f(x: => Int): Int -class C with +class C: def f(x: => String): Int = x.length @targetName("f2") def f(x: => Int): Int = x -object B1 extends C, T with +object B1 extends C, T: @targetName("f2") override def f(x: => Int): Int = x + 1 -object B2 extends C, T with +object B2 extends C, T: override def f(x: => String): Int = x.length + 1 @targetName("fooString") def foo(ps: String*) : Unit = println(s"strings: $ps") diff --git a/tests/run/typable.scala b/tests/run/typable.scala index b47cde8eb3e8..7fe253023740 100644 --- a/tests/run/typable.scala +++ b/tests/run/typable.scala @@ -1,6 +1,6 @@ import scala.reflect._ -object Test with +object Test: def main(args: Array[String]): Unit = assert(f[String]) assert(!f[Int]) diff --git a/tests/run/unambiref.scala b/tests/run/unambiref.scala index d8c74d6ed919..1dc617aefa4c 100644 --- a/tests/run/unambiref.scala +++ b/tests/run/unambiref.scala @@ -1,5 +1,5 @@ -class A(val x: Int) with - class B extends A(2) with +class A(val x: Int): + class B extends A(2): println(x) @main def Test = diff --git a/tests/semanticdb/expect/Enums.expect.scala b/tests/semanticdb/expect/Enums.expect.scala index 0a9888c07457..d74e49ccf98d 100644 --- a/tests/semanticdb/expect/Enums.expect.scala +++ b/tests/semanticdb/expect/Enums.expect.scala @@ -1,17 +1,17 @@ -object Enums/*<-_empty_::Enums.*/ with +object Enums/*<-_empty_::Enums.*/: import <:_empty_::Enums.`<:<`.*/._ - enum Colour/*<-_empty_::Enums.Colour#*/ with + enum Colour/*<-_empty_::Enums.Colour#*/: import Colour/*->_empty_::Enums.Colour.*/.Red/*->_empty_::Enums.Colour.Red.*/ case Red/*<-_empty_::Enums.Colour.Red.*/, Green/*<-_empty_::Enums.Colour.Green.*/, Blue/*<-_empty_::Enums.Colour.Blue.*/ - enum Directions/*<-_empty_::Enums.Directions#*/ with + enum Directions/*<-_empty_::Enums.Directions#*/: case North/*<-_empty_::Enums.Directions.North.*/, East/*<-_empty_::Enums.Directions.East.*/, South/*<-_empty_::Enums.Directions.South.*/, West/*<-_empty_::Enums.Directions.West.*/ - enum Suits/*<-_empty_::Enums.Suits#*/ derives /*->scala::CanEqual.derived.*/CanEqual with + enum Suits/*<-_empty_::Enums.Suits#*/ derives /*->scala::CanEqual.derived.*/CanEqual: case Hearts/*<-_empty_::Enums.Suits.Hearts.*/, Spades/*<-_empty_::Enums.Suits.Spades.*/, Clubs/*<-_empty_::Enums.Suits.Clubs.*/, Diamonds/*<-_empty_::Enums.Suits.Diamonds.*/ - object Suits/*<-_empty_::Enums.Suits.*/ with + object Suits/*<-_empty_::Enums.Suits.*/: extension (suit/*<-_empty_::Enums.Suits.isRed().(suit)*/: Suits/*->_empty_::Enums.Suits#*/) def isRed/*<-_empty_::Enums.Suits.isRed().*/: Boolean/*->scala::Boolean#*/ = suit/*->_empty_::Enums.Suits.isRed().(suit)*/ ==/*->scala::Any#`==`().*/ Hearts/*->_empty_::Enums.Suits.Hearts.*/ ||/*->scala::Boolean#`||`().*/ suit/*->_empty_::Enums.Suits.isRed().(suit)*/ ==/*->scala::Any#`==`().*/ Diamonds/*->_empty_::Enums.Suits.Diamonds.*/ @@ -19,7 +19,7 @@ object Enums/*<-_empty_::Enums.*/ with case Spades/*->_empty_::Enums.Suits.Spades.*/ | Clubs/*->_empty_::Enums.Suits.Clubs.*/ => true case _ => false - enum WeekDays/*<-_empty_::Enums.WeekDays#*/ with + enum WeekDays/*<-_empty_::Enums.WeekDays#*/: case Monday/*<-_empty_::Enums.WeekDays.Monday.*/ case Tuesday/*<-_empty_::Enums.WeekDays.Tuesday.*/ case Wednesday/*<-_empty_::Enums.WeekDays.Wednesday.*/ @@ -28,25 +28,25 @@ object Enums/*<-_empty_::Enums.*/ with case Saturday/*<-_empty_::Enums.WeekDays.Saturday.*/ case Sunday/*<-_empty_::Enums.WeekDays.Sunday.*/ - enum Coin/*<-_empty_::Enums.Coin#*/(value/*<-_empty_::Enums.Coin#value.*/: Int/*->scala::Int#*/) with + enum Coin/*<-_empty_::Enums.Coin#*/(value/*<-_empty_::Enums.Coin#value.*/: Int/*->scala::Int#*/): case Penny/*<-_empty_::Enums.Coin.Penny.*/ extends Coin/*->_empty_::Enums.Coin#*/(1)/*->scala::runtime::EnumValue#*/ case Nickel/*<-_empty_::Enums.Coin.Nickel.*/ extends Coin/*->_empty_::Enums.Coin#*/(5)/*->scala::runtime::EnumValue#*/ case Dime/*<-_empty_::Enums.Coin.Dime.*/ extends Coin/*->_empty_::Enums.Coin#*/(10)/*->scala::runtime::EnumValue#*/ case Quarter/*<-_empty_::Enums.Coin.Quarter.*/ extends Coin/*->_empty_::Enums.Coin#*/(25)/*->scala::runtime::EnumValue#*/ case Dollar/*<-_empty_::Enums.Coin.Dollar.*/ extends Coin/*->_empty_::Enums.Coin#*/(100)/*->scala::runtime::EnumValue#*/ - enum Maybe/*<-_empty_::Enums.Maybe#*/[+A/*<-_empty_::Enums.Maybe#[A]*/] with + enum Maybe/*<-_empty_::Enums.Maybe#*/[+A/*<-_empty_::Enums.Maybe#[A]*/]: case Just/*<-_empty_::Enums.Maybe.Just#*/(value/*<-_empty_::Enums.Maybe.Just#value.*/: A/*->_empty_::Enums.Maybe.Just#[A]*/) case None/*<-_empty_::Enums.Maybe.None.*//*->scala::runtime::EnumValue#*/ - enum Tag/*<-_empty_::Enums.Tag#*/[A/*<-_empty_::Enums.Tag#[A]*/] with + enum Tag/*<-_empty_::Enums.Tag#*/[A/*<-_empty_::Enums.Tag#[A]*/]: case IntTag/*<-_empty_::Enums.Tag.IntTag.*/ extends Tag/*->_empty_::Enums.Tag#*/[Int/*->scala::Int#*/]/*->scala::runtime::EnumValue#*/ case BooleanTag/*<-_empty_::Enums.Tag.BooleanTag.*/ extends Tag/*->_empty_::Enums.Tag#*/[Boolean/*->scala::Boolean#*/]/*->scala::runtime::EnumValue#*/ - enum <:_empty_::Enums.`<:<`.Refl#[C]*/ <:_empty_::Enums.`<:<`#*/ C/*->_empty_::Enums.`<:<`.Refl#[C]*/) - object <:_empty_::Enums.`<:<`.given_T().[T]*/ <:_empty_::Enums.`<:<`#*/ T/*->_empty_::Enums.`<:<`.given_T().[T]*/) = Refl/*->_empty_::Enums.`<:<`.Refl.*//*->_empty_::Enums.`<:<`.Refl.apply().*/() extension [A/*<-_empty_::Enums.unwrap().[A]*/, B/*<-_empty_::Enums.unwrap().[B]*/](opt/*<-_empty_::Enums.unwrap().(opt)*/: Option/*->scala::Option#*/[A/*->_empty_::Enums.unwrap().[A]*/]) def unwrap/*<-_empty_::Enums.unwrap().*/(using ev/*<-_empty_::Enums.unwrap().(ev)*/: A/*->_empty_::Enums.unwrap().[A]*/ <:_empty_::Enums.`<:<`#*/ Option/*->scala::Option#*/[B/*->_empty_::Enums.unwrap().[B]*/]): Option/*->scala::Option#*/[B/*->_empty_::Enums.unwrap().[B]*/] = ev/*->_empty_::Enums.unwrap().(ev)*/ match @@ -54,7 +54,7 @@ object Enums/*<-_empty_::Enums.*/ with val some1/*<-_empty_::Enums.some1.*/ = /*->_empty_::Enums.unwrap().*/Some/*->scala::Some.*//*->scala::Some.apply().*/(Some/*->scala::Some.*//*->scala::Some.apply().*/(1)).unwrap/*->_empty_::Enums.`<:<`.given_T().*/ - enum Planet/*<-_empty_::Enums.Planet#*/(mass/*<-_empty_::Enums.Planet#mass.*/: Double/*->scala::Double#*/, radius/*<-_empty_::Enums.Planet#radius.*/: Double/*->scala::Double#*/) extends Enum/*->java::lang::Enum#*/[Planet/*->_empty_::Enums.Planet#*/]/*->java::lang::Enum#``().*/ with + enum Planet/*<-_empty_::Enums.Planet#*/(mass/*<-_empty_::Enums.Planet#mass.*/: Double/*->scala::Double#*/, radius/*<-_empty_::Enums.Planet#radius.*/: Double/*->scala::Double#*/) extends Enum/*->java::lang::Enum#*/[Planet/*->_empty_::Enums.Planet#*/]/*->java::lang::Enum#``().*/: private final val G/*<-_empty_::Enums.Planet#G.*/ = 6.67300E-11 def surfaceGravity/*<-_empty_::Enums.Planet#surfaceGravity().*/ = G/*->_empty_::Enums.Planet#G.*/ */*->scala::Double#`*`(+6).*/ mass/*->_empty_::Enums.Planet#mass.*/ //*->scala::Double#`::`(+6).*/ (radius/*->_empty_::Enums.Planet#radius.*/ */*->scala::Double#`*`(+6).*/ radius/*->_empty_::Enums.Planet#radius.*/) def surfaceWeight/*<-_empty_::Enums.Planet#surfaceWeight().*/(otherMass/*<-_empty_::Enums.Planet#surfaceWeight().(otherMass)*/: Double/*->scala::Double#*/) = otherMass/*->_empty_::Enums.Planet#surfaceWeight().(otherMass)*/ */*->scala::Double#`*`(+6).*/ surfaceGravity/*->_empty_::Enums.Planet#surfaceGravity().*/ diff --git a/tests/semanticdb/expect/Enums.scala b/tests/semanticdb/expect/Enums.scala index 353b9206f905..3d666fb618a9 100644 --- a/tests/semanticdb/expect/Enums.scala +++ b/tests/semanticdb/expect/Enums.scala @@ -1,17 +1,17 @@ -object Enums with +object Enums: import <:<._ - enum Colour with + enum Colour: import Colour.Red case Red, Green, Blue - enum Directions with + enum Directions: case North, East, South, West - enum Suits derives CanEqual with + enum Suits derives CanEqual: case Hearts, Spades, Clubs, Diamonds - object Suits with + object Suits: extension (suit: Suits) def isRed: Boolean = suit == Hearts || suit == Diamonds @@ -19,7 +19,7 @@ object Enums with case Spades | Clubs => true case _ => false - enum WeekDays with + enum WeekDays: case Monday case Tuesday case Wednesday @@ -28,25 +28,25 @@ object Enums with case Saturday case Sunday - enum Coin(value: Int) with + enum Coin(value: Int): case Penny extends Coin(1) case Nickel extends Coin(5) case Dime extends Coin(10) case Quarter extends Coin(25) case Dollar extends Coin(100) - enum Maybe[+A] with + enum Maybe[+A]: case Just(value: A) case None - enum Tag[A] with + enum Tag[A]: case IntTag extends Tag[Int] case BooleanTag extends Tag[Boolean] - enum <:<[-A, B] with + enum <:<[-A, B]: case Refl[C]() extends (C <:< C) - object <:< with + object <:< : given [T]: (T <:< T) = Refl() extension [A, B](opt: Option[A]) def unwrap(using ev: A <:< Option[B]): Option[B] = ev match @@ -54,7 +54,7 @@ object Enums with val some1 = Some(Some(1)).unwrap - enum Planet(mass: Double, radius: Double) extends Enum[Planet] with + enum Planet(mass: Double, radius: Double) extends Enum[Planet]: private final val G = 6.67300E-11 def surfaceGravity = G * mass / (radius * radius) def surfaceWeight(otherMass: Double) = otherMass * surfaceGravity diff --git a/tests/semanticdb/expect/Givens.expect.scala b/tests/semanticdb/expect/Givens.expect.scala index 4089ad837ed3..126c1f8e9919 100644 --- a/tests/semanticdb/expect/Givens.expect.scala +++ b/tests/semanticdb/expect/Givens.expect.scala @@ -1,7 +1,7 @@ package a package b -object Givens/*<-a::b::Givens.*/ with +object Givens/*<-a::b::Givens.*/: extension [A/*<-a::b::Givens.sayHello().[A]*/](any/*<-a::b::Givens.sayHello().(any)*/: A/*->a::b::Givens.sayHello().[A]*/) def sayHello/*<-a::b::Givens.sayHello().*/ = s"/*->scala::StringContext.apply().*/Hello, I am $any/*->a::b::Givens.sayHello().(any)*/"/*->scala::StringContext#s().*/ @@ -14,7 +14,7 @@ object Givens/*<-a::b::Givens.*/ with val goodbye1/*<-a::b::Givens.goodbye1.*/ = /*->a::b::Givens.sayGoodbye().*/1.sayGoodbye val soLong1/*<-a::b::Givens.soLong1.*/ = /*->a::b::Givens.saySoLong().*/1.saySoLong - trait Monoid/*<-a::b::Givens.Monoid#*/[A/*<-a::b::Givens.Monoid#[A]*/] with + trait Monoid/*<-a::b::Givens.Monoid#*/[A/*<-a::b::Givens.Monoid#[A]*/]: def empty/*<-a::b::Givens.Monoid#empty().*/: A/*->a::b::Givens.Monoid#[A]*/ extension (x/*<-a::b::Givens.Monoid#combine().(x)*/: A/*->a::b::Givens.Monoid#[A]*/) def combine/*<-a::b::Givens.Monoid#combine().*/(y/*<-a::b::Givens.Monoid#combine().(y)*/: A/*->a::b::Givens.Monoid#[A]*/): A/*->a::b::Givens.Monoid#[A]*/ diff --git a/tests/semanticdb/expect/Givens.scala b/tests/semanticdb/expect/Givens.scala index 5f22df9416b6..819d70cfadca 100644 --- a/tests/semanticdb/expect/Givens.scala +++ b/tests/semanticdb/expect/Givens.scala @@ -1,7 +1,7 @@ package a package b -object Givens with +object Givens: extension [A](any: A) def sayHello = s"Hello, I am $any" @@ -14,7 +14,7 @@ object Givens with val goodbye1 = 1.sayGoodbye val soLong1 = 1.saySoLong - trait Monoid[A] with + trait Monoid[A]: def empty: A extension (x: A) def combine(y: A): A diff --git a/tests/semanticdb/expect/inlineconsume.expect.scala b/tests/semanticdb/expect/inlineconsume.expect.scala index 7126236c1205..8ffe432064d4 100644 --- a/tests/semanticdb/expect/inlineconsume.expect.scala +++ b/tests/semanticdb/expect/inlineconsume.expect.scala @@ -2,5 +2,5 @@ package inlineconsume import inlinedefs.FakePredef/*->inlinedefs::FakePredef.*/.assert/*->inlinedefs::FakePredef.assert().*/ -class Foo/*<-inlineconsume::Foo#*/ with +class Foo/*<-inlineconsume::Foo#*/: def test/*<-inlineconsume::Foo#test().*/ = assert/*->inlinedefs::FakePredef.assert().*/(3 >/*->scala::Int#`>`(+3).*/ 2) diff --git a/tests/semanticdb/expect/inlineconsume.scala b/tests/semanticdb/expect/inlineconsume.scala index 3c15686f66a9..db7130c50515 100644 --- a/tests/semanticdb/expect/inlineconsume.scala +++ b/tests/semanticdb/expect/inlineconsume.scala @@ -2,5 +2,5 @@ package inlineconsume import inlinedefs.FakePredef.assert -class Foo with +class Foo: def test = assert(3 > 2) diff --git a/tests/semanticdb/expect/inlinedefs.expect.scala b/tests/semanticdb/expect/inlinedefs.expect.scala index 9e3da263e558..c0e1a8913c0a 100644 --- a/tests/semanticdb/expect/inlinedefs.expect.scala +++ b/tests/semanticdb/expect/inlinedefs.expect.scala @@ -1,6 +1,6 @@ package inlinedefs -object FakePredef/*<-inlinedefs::FakePredef.*/ with +object FakePredef/*<-inlinedefs::FakePredef.*/: /** Super long padded documentation * Lorem ipsum dolor sit amet, consectetur adipiscing elit, diff --git a/tests/semanticdb/expect/inlinedefs.scala b/tests/semanticdb/expect/inlinedefs.scala index 0598d2dee4d0..7902a9750b4b 100644 --- a/tests/semanticdb/expect/inlinedefs.scala +++ b/tests/semanticdb/expect/inlinedefs.scala @@ -1,6 +1,6 @@ package inlinedefs -object FakePredef with +object FakePredef: /** Super long padded documentation * Lorem ipsum dolor sit amet, consectetur adipiscing elit, diff --git a/tests/sjs-junit/test/org/scalajs/testsuite/compiler/EnumTestScala3.scala b/tests/sjs-junit/test/org/scalajs/testsuite/compiler/EnumTestScala3.scala index 93b135de6576..01bdb6ccc954 100644 --- a/tests/sjs-junit/test/org/scalajs/testsuite/compiler/EnumTestScala3.scala +++ b/tests/sjs-junit/test/org/scalajs/testsuite/compiler/EnumTestScala3.scala @@ -3,7 +3,7 @@ package org.scalajs.testsuite.compiler import org.junit.Assert._ import org.junit.Test -class EnumTestScala3 with +class EnumTestScala3: import EnumTestScala3._ @Test def testColor1(): Unit = @@ -141,26 +141,26 @@ class EnumTestScala3 with end testOpt -object EnumTestScala3 with +object EnumTestScala3: - enum Color1 derives CanEqual with + enum Color1 derives CanEqual: case Red, Green, Blue - enum Color2 extends java.lang.Enum[Color2] derives CanEqual with + enum Color2 extends java.lang.Enum[Color2] derives CanEqual: case Red, Green, Blue // test "non-simple" cases with anonymous subclasses - enum Currency1(val dollarValue: Double) derives CanEqual with + enum Currency1(val dollarValue: Double) derives CanEqual: case Dollar extends Currency1(1.0) case SwissFanc extends Currency1(1.09) case Euro extends Currency1(1.18) - enum Currency2(val dollarValue: Double) extends java.lang.Enum[Currency2] derives CanEqual with + enum Currency2(val dollarValue: Double) extends java.lang.Enum[Currency2] derives CanEqual: case Dollar extends Currency2(1.0) case SwissFanc extends Currency2(1.09) case Euro extends Currency2(1.18) - enum Opt[+T] with + enum Opt[+T]: case Sm[+T1](value: T1) extends Opt[T1] case Nn extends Opt[Nothing]