diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index e66c71731b4f..0e65a254dcf5 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -978,8 +978,8 @@ object desugar { // we can reuse the constructor parameters; no derived params are needed. DefDef( className.toTermName, joinParams(constrTparams, defParamss), classTypeRef, creatorExpr - ) .withMods(companionMods | mods.flags.toTermFlags & (GivenOrImplicit | Inline) | finalFlag) - .withSpan(cdef.span) :: Nil + ).withMods(companionMods | mods.flags.toTermFlags & (GivenOrImplicit | Inline) | finalFlag) + .withSpan(cdef.span) :: Nil } val self1 = { diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index aa55380ba634..b766b9046ce3 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -2078,12 +2078,12 @@ class Namer { typer: Typer => case _ => def inferredResultType( - mdef: ValOrDefDef, - sym: Symbol, - paramss: List[List[Symbol]], - paramFn: Type => Type, - fallbackProto: Type - )(using Context): Type = + mdef: ValOrDefDef, + sym: Symbol, + paramss: List[List[Symbol]], + paramFn: Type => Type, + fallbackProto: Type + )(using Context): Type = /** A type for this definition that might be inherited from elsewhere: * If this is a setter parameter, the corresponding getter type. diff --git a/compiler/test/dotc/pos-test-pickling.blacklist b/compiler/test/dotc/pos-test-pickling.blacklist index d8f4fcc10c04..032b53150e49 100644 --- a/compiler/test/dotc/pos-test-pickling.blacklist +++ b/compiler/test/dotc/pos-test-pickling.blacklist @@ -135,7 +135,6 @@ parsercombinators-new-syntax.scala hylolib-deferred-given hylolib-cb hylolib -infer-tracked-parsercombinators-givens.scala # typecheckErrors method unpickling i21415.scala diff --git a/tests/pos/infer-tracked-parsercombinators-givens.scala b/tests/pos/infer-tracked-parsercombinators-givens.scala deleted file mode 100644 index c183eb13a9ea..000000000000 --- a/tests/pos/infer-tracked-parsercombinators-givens.scala +++ /dev/null @@ -1,54 +0,0 @@ -import scala.language.experimental.modularity -import scala.language.future -import collection.mutable - -/// A parser combinator. -trait Combinator[T]: - - /// The context from which elements are being parsed, typically a stream of tokens. - type Context - /// The element being parsed. - type Element - - extension (self: T) - /// Parses and returns an element from `context`. - def parse(context: Context): Option[Element] -end Combinator - -final case class Apply[C, E](action: C => Option[E]) -final case class Combine[A, B](first: A, second: B) - -given apply: [C, E] => Combinator[Apply[C, E]] { - type Context = C - type Element = E - extension(self: Apply[C, E]) { - def parse(context: C): Option[E] = self.action(context) - } -} - -given combine[A, B](using - tracked val f: Combinator[A], - tracked val s: Combinator[B] { type Context = f.Context } -): Combinator[Combine[A, B]] with { - type Context = f.Context - type Element = (f.Element, s.Element) - extension(self: Combine[A, B]) { - def parse(context: Context): Option[Element] = ??? - } -} - -extension [A] (buf: mutable.ListBuffer[A]) def popFirst() = - if buf.isEmpty then None - else try Some(buf.head) finally buf.remove(0) - -@main def hello: Unit = { - val source = (0 to 10).toList - val stream = source.to(mutable.ListBuffer) - - val n = Apply[mutable.ListBuffer[Int], Int](s => s.popFirst()) - val m = Combine(n, n) - - val r = m.parse(stream) // error: type mismatch, found `mutable.ListBuffer[Int]`, required `?1.Context` - val rc: Option[(Int, Int)] = r - // it would be great if this worked -} diff --git a/tests/pos/infer-tracked.scala b/tests/pos/infer-tracked.scala index 8c8d7b1de126..08caac1c46c1 100644 --- a/tests/pos/infer-tracked.scala +++ b/tests/pos/infer-tracked.scala @@ -25,6 +25,11 @@ case class K(c: C): case class L(c: C): type T = c.T +class M + +given mInst: (c: C) => M: + def foo: c.T = c.foo + def Test = val c = new C: type T = Int @@ -33,8 +38,7 @@ def Test = val f = new F(c) val _: Int = f.result - // Not really possible to work with inference in Namer, should emit a lint - // val g = new G(c) + // val g = new G(c) // current limitation of infering in Namer, should emit a lint // val _: Int = g.result val h = new H(c) @@ -51,3 +55,6 @@ def Test = val l = L(c) summon[l.T =:= Int] + + // val m = mInst(using c) // current limitation, we infer tracked after this desugaring + // val _: Int = m.foo