diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 0edefff765b3..00f6f0fe0a1a 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -2049,8 +2049,9 @@ trait Applications extends Compatibility { record("resolveOverloaded") // A local cache for widenings of alternatives. - // If a type is provisonal, its denotation will not cached. - // Hence, using `widen` on provisional types everywhere will recompute denotations repeatedly. + // The logic here heavily relies on `widen` to resolve overloadings. However, `widen` + // would compute the denotation, and the denotation of a provisional type is not cached, + // so we would end up computing the same denotation multiple times. // Given the denotation will not change in this part, we can safely cache the result. val altsWidenMap = mutable.HashMap.empty[TermRef, Type] def widen(ref: TermRef): Type = altsWidenMap.getOrElseUpdate(ref, ref.widen) diff --git a/tests/pos/i20217.scala b/tests/pos/i20217.scala new file mode 100644 index 000000000000..0f4e0a4c9620 --- /dev/null +++ b/tests/pos/i20217.scala @@ -0,0 +1,42 @@ +// A simplifies version of PartiallyAppliedStruct from smithy4s + +trait Field[S, A] +trait Schema[S] + +class PartiallyAppliedStruct[S](): + def apply[A0](a0: Field[S, A0])(const: (A0) => S): Schema[S] = ??? + def apply[A0, A1](a0: Field[S, A0], a1: Field[S, A1])(const: (A0, A1) => S): Schema[S] = ??? + def apply[A0, A1, A2](a0: Field[S, A0], a1: Field[S, A1], a2: Field[S, A2])(const: (A0, A1, A2) => S): Schema[S] = ??? + def apply[A0, A1, A2, A3](a0: Field[S, A0], a1: Field[S, A1], a2: Field[S, A2], a3: Field[S, A3])(const: (A0, A1, A2, A3) => S): Schema[S] = ??? + def apply[A0, A1, A2, A3, A4](a0: Field[S, A0], a1: Field[S, A1], a2: Field[S, A2], a3: Field[S, A3], a4: Field[S, A4])(const: (A0, A1, A2, A3, A4) => S): Schema[S] = ??? + def apply[A0, A1, A2, A3, A4, A5](a0: Field[S, A0], a1: Field[S, A1], a2: Field[S, A2], a3: Field[S, A3], a4: Field[S, A4], a5: Field[S, A5])(const: (A0, A1, A2, A3, A4, A5) => S): Schema[S] = ??? + def apply[A0, A1, A2, A3, A4, A5, A6](a0: Field[S, A0], a1: Field[S, A1], a2: Field[S, A2], a3: Field[S, A3], a4: Field[S, A4], a5: Field[S, A5], a6: Field[S, A6])(const: (A0, A1, A2, A3, A4, A5, A6) => S): Schema[S] = ??? + def apply[A0, A1, A2, A3, A4, A5, A6, A7](a0: Field[S, A0], a1: Field[S, A1], a2: Field[S, A2], a3: Field[S, A3], a4: Field[S, A4], a5: Field[S, A5], a6: Field[S, A6], a7: Field[S, A7])(const: (A0, A1, A2, A3, A4, A5, A6, A7) => S): Schema[S] = ??? + def apply[A0, A1, A2, A3, A4, A5, A6, A7, A8](a0: Field[S, A0], a1: Field[S, A1], a2: Field[S, A2], a3: Field[S, A3], a4: Field[S, A4], a5: Field[S, A5], a6: Field[S, A6], a7: Field[S, A7], a8: Field[S, A8])(const: (A0, A1, A2, A3, A4, A5, A6, A7, A8) => S): Schema[S] = ??? + def apply[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9](a0: Field[S, A0], a1: Field[S, A1], a2: Field[S, A2], a3: Field[S, A3], a4: Field[S, A4], a5: Field[S, A5], a6: Field[S, A6], a7: Field[S, A7], a8: Field[S, A8], a9: Field[S, A9])(const: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9) => S): Schema[S] = ??? + def apply[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10](a0: Field[S, A0], a1: Field[S, A1], a2: Field[S, A2], a3: Field[S, A3], a4: Field[S, A4], a5: Field[S, A5], a6: Field[S, A6], a7: Field[S, A7], a8: Field[S, A8], a9: Field[S, A9], a10: Field[S, A10])(const: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) => S): Schema[S] = ??? + def apply[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11](a0: Field[S, A0], a1: Field[S, A1], a2: Field[S, A2], a3: Field[S, A3], a4: Field[S, A4], a5: Field[S, A5], a6: Field[S, A6], a7: Field[S, A7], a8: Field[S, A8], a9: Field[S, A9], a10: Field[S, A10], a11: Field[S, A11])(const: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11) => S): Schema[S] = ??? + def apply[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12](a0: Field[S, A0], a1: Field[S, A1], a2: Field[S, A2], a3: Field[S, A3], a4: Field[S, A4], a5: Field[S, A5], a6: Field[S, A6], a7: Field[S, A7], a8: Field[S, A8], a9: Field[S, A9], a10: Field[S, A10], a11: Field[S, A11], a12: Field[S, A12])(const: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12) => S): Schema[S] = ??? + def apply[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13](a0: Field[S, A0], a1: Field[S, A1], a2: Field[S, A2], a3: Field[S, A3], a4: Field[S, A4], a5: Field[S, A5], a6: Field[S, A6], a7: Field[S, A7], a8: Field[S, A8], a9: Field[S, A9], a10: Field[S, A10], a11: Field[S, A11], a12: Field[S, A12], a13: Field[S, A13])(const: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13) => S): Schema[S] = ??? + def apply[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14](a0: Field[S, A0], a1: Field[S, A1], a2: Field[S, A2], a3: Field[S, A3], a4: Field[S, A4], a5: Field[S, A5], a6: Field[S, A6], a7: Field[S, A7], a8: Field[S, A8], a9: Field[S, A9], a10: Field[S, A10], a11: Field[S, A11], a12: Field[S, A12], a13: Field[S, A13], a14: Field[S, A14])(const: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14) => S): Schema[S] = ??? + def apply[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15](a0: Field[S, A0], a1: Field[S, A1], a2: Field[S, A2], a3: Field[S, A3], a4: Field[S, A4], a5: Field[S, A5], a6: Field[S, A6], a7: Field[S, A7], a8: Field[S, A8], a9: Field[S, A9], a10: Field[S, A10], a11: Field[S, A11], a12: Field[S, A12], a13: Field[S, A13], a14: Field[S, A14], a15: Field[S, A15])(const: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15) => S): Schema[S] = ??? + def apply[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16](a0: Field[S, A0], a1: Field[S, A1], a2: Field[S, A2], a3: Field[S, A3], a4: Field[S, A4], a5: Field[S, A5], a6: Field[S, A6], a7: Field[S, A7], a8: Field[S, A8], a9: Field[S, A9], a10: Field[S, A10], a11: Field[S, A11], a12: Field[S, A12], a13: Field[S, A13], a14: Field[S, A14], a15: Field[S, A15], a16: Field[S, A16])(const: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16) => S): Schema[S] = ??? + def apply[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17](a0: Field[S, A0], a1: Field[S, A1], a2: Field[S, A2], a3: Field[S, A3], a4: Field[S, A4], a5: Field[S, A5], a6: Field[S, A6], a7: Field[S, A7], a8: Field[S, A8], a9: Field[S, A9], a10: Field[S, A10], a11: Field[S, A11], a12: Field[S, A12], a13: Field[S, A13], a14: Field[S, A14], a15: Field[S, A15], a16: Field[S, A16], a17: Field[S, A17])(const: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17) => S): Schema[S] = ??? + def apply[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18](a0: Field[S, A0], a1: Field[S, A1], a2: Field[S, A2], a3: Field[S, A3], a4: Field[S, A4], a5: Field[S, A5], a6: Field[S, A6], a7: Field[S, A7], a8: Field[S, A8], a9: Field[S, A9], a10: Field[S, A10], a11: Field[S, A11], a12: Field[S, A12], a13: Field[S, A13], a14: Field[S, A14], a15: Field[S, A15], a16: Field[S, A16], a17: Field[S, A17], a18: Field[S, A18])(const: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18) => S): Schema[S] = ??? + def apply[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19](a0: Field[S, A0], a1: Field[S, A1], a2: Field[S, A2], a3: Field[S, A3], a4: Field[S, A4], a5: Field[S, A5], a6: Field[S, A6], a7: Field[S, A7], a8: Field[S, A8], a9: Field[S, A9], a10: Field[S, A10], a11: Field[S, A11], a12: Field[S, A12], a13: Field[S, A13], a14: Field[S, A14], a15: Field[S, A15], a16: Field[S, A16], a17: Field[S, A17], a18: Field[S, A18], a19: Field[S, A19])(const: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19) => S): Schema[S] = ??? + def apply[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20](a0: Field[S, A0], a1: Field[S, A1], a2: Field[S, A2], a3: Field[S, A3], a4: Field[S, A4], a5: Field[S, A5], a6: Field[S, A6], a7: Field[S, A7], a8: Field[S, A8], a9: Field[S, A9], a10: Field[S, A10], a11: Field[S, A11], a12: Field[S, A12], a13: Field[S, A13], a14: Field[S, A14], a15: Field[S, A15], a16: Field[S, A16], a17: Field[S, A17], a18: Field[S, A18], a19: Field[S, A19], a20: Field[S, A20])(const: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20) => S): Schema[S] = ??? + def apply[A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21](a0: Field[S, A0], a1: Field[S, A1], a2: Field[S, A2], a3: Field[S, A3], a4: Field[S, A4], a5: Field[S, A5], a6: Field[S, A6], a7: Field[S, A7], a8: Field[S, A8], a9: Field[S, A9], a10: Field[S, A10], a11: Field[S, A11], a12: Field[S, A12], a13: Field[S, A13], a14: Field[S, A14], a15: Field[S, A15], a16: Field[S, A16], a17: Field[S, A17], a18: Field[S, A18], a19: Field[S, A19], a20: Field[S, A20], a21: Field[S, A21])(const: (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21) => S): Schema[S] = ??? + +def struct[S] = new PartiallyAppliedStruct[S]() + + +def test[S, T](a: Field[S, Int], b: Field[S, String], c: Field[S, T], defaultValue: S) = + val s1: Schema[S] = struct(a)(_ => defaultValue) + val s2: Schema[S] = struct(a, b)((_, _) => defaultValue) + val s3: Schema[S] = struct(a, b, c)((_, _, _) => defaultValue) + val s4: Schema[S] = struct(a, b, c, a, b, c)((_, _, _, _, _, _) => defaultValue) + + val s5 = struct(a)(_ => defaultValue) + val s6 = struct(a, b)((_, _) => defaultValue) + val s7 = struct(a, b, c)((_, _, _) => defaultValue) + val s8 = struct(a, b, c, a, b, c)((_, _, _, _, _, _) => defaultValue)