From e8153e81652a5effe9415eb9e5d44dc700046744 Mon Sep 17 00:00:00 2001 From: peng Date: Tue, 21 Nov 2023 02:39:42 -0500 Subject: [PATCH 1/4] fix #110 --- build.gradle.kts | 1 + .../splain/SplainFormattingExtension.scala | 22 +++++++++++++------ .../latest/splain/TyperCompatViews.scala | 8 +++---- .../splain/builtin/BasicSpec/__direct/check | 9 +------- .../VTypeDetailReductionSpec/__direct/check | 4 ++-- .../plugin/VTypeDetailSpec/__direct/check | 18 +++++++++++++++ .../scala/splain/plugin/VTypeDetailSpec.scala | 19 ++++++++++++++++ .../splain/builtin/BasicSpec/__direct/check | 10 +-------- 8 files changed, 60 insertions(+), 31 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index d2551d1..c370aad 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -358,6 +358,7 @@ idea { ".gradle", "gradle", "spike", + ".history" ) } } \ No newline at end of file diff --git a/core/src/main/scala-2.13.7+/latest/splain/SplainFormattingExtension.scala b/core/src/main/scala-2.13.7+/latest/splain/SplainFormattingExtension.scala index c4f7036..3e81db6 100644 --- a/core/src/main/scala-2.13.7+/latest/splain/SplainFormattingExtension.scala +++ b/core/src/main/scala-2.13.7+/latest/splain/SplainFormattingExtension.scala @@ -395,9 +395,17 @@ trait SplainFormattingExtension extends typechecker.splain.SplainFormatting with if (isAux(tpe)) tpe else { - - val result = tpe.dealias - result + val result = tpe.dealias.normalize + result match { + case p: PolyType => + val target = dealias(p.resultType) + val _p = p.copy( + resultType = target + ) + _p + case _ => + result + } } } @@ -608,11 +616,11 @@ trait SplainFormattingExtension extends typechecker.splain.SplainFormatting with protected def formatDiffImplNoDisambiguation(found: Type, req: Type, top: Boolean): Formatted = { - val (left, right) = dealias(found) -> dealias(req) + val reduced = Seq(found, req).map(dealias) + val Seq(left, right) = reduced - val normalized = Seq(left, right).map(_.normalize).distinct - if (normalized.size == 1) { - val only = normalized.head + if (reduced.distinct.size == 1) { + val only = reduced.head val result = formatType(only, top) val basedOn = Seq(found, req).distinct diff --git a/core/src/main/scala-2.13.7+/latest/splain/TyperCompatViews.scala b/core/src/main/scala-2.13.7+/latest/splain/TyperCompatViews.scala index ab50655..cc7705f 100644 --- a/core/src/main/scala-2.13.7+/latest/splain/TyperCompatViews.scala +++ b/core/src/main/scala-2.13.7+/latest/splain/TyperCompatViews.scala @@ -9,11 +9,9 @@ trait TyperCompatViews { case class TypeView(self: Type) { - lazy val extractArgs: List[global.Type] = self match { - // PolyType handling is removed for being unsound - case t: AliasTypeRef if !isAux(self) => - t.betaReduce.typeArgs.map(a => if (a.typeSymbolDirect.isTypeParameter) WildcardType else a) - case _ => self.typeArgs + lazy val extractArgs: List[global.Type] = { + + self.typeArgs } lazy val noArgType: Type = if (extractArgs.nonEmpty) { diff --git a/core/src/test/resources/splain/builtin/BasicSpec/__direct/check b/core/src/test/resources/splain/builtin/BasicSpec/__direct/check index 3227543..8935e74 100644 --- a/core/src/test/resources/splain/builtin/BasicSpec/__direct/check +++ b/core/src/test/resources/splain/builtin/BasicSpec/__direct/check @@ -143,14 +143,7 @@ f invalid because implicitly[String] ^ newSource1.scala:11: error: implicit error; -!I e: - DeepHole.C1[ - DeepHole.T3[ - DeepHole.T1[List[String], ?], - DeepHole.T2[DeepHole.Id, DeepHole.C4, ?], - ? - ] - ] +!I e: DeepHole.C1[[Z]DeepHole.C2[DeepHole.T1,DeepHole.T2,Z]] implicitly[C1[T3]] ^ newSource1.scala:9: error: implicit error; diff --git a/core/src/test/resources/splain/plugin/VTypeDetailReductionSpec/__direct/check b/core/src/test/resources/splain/plugin/VTypeDetailReductionSpec/__direct/check index 5d9ac76..e83b701 100644 --- a/core/src/test/resources/splain/plugin/VTypeDetailReductionSpec/__direct/check +++ b/core/src/test/resources/splain/plugin/VTypeDetailReductionSpec/__direct/check @@ -10,7 +10,7 @@ val x: vecInt.Head = ??? : Option[String] ^ newSource1.scala:8: error: implicit error; !I e: - Option[Int] (reduced from) { FoundReqVsImplicit.vecInt.Head[Int] } =:= + Option[Int] (reduced from) { FoundReqVsImplicit.vecInt.Head } =:= Option[String] Cannot prove that FoundReqVsImplicit.vecInt.Head =:= Option[String]. @@ -19,6 +19,6 @@ implicitly[vecInt.Head =:= Option[String]] newSource1.scala:10: error: type mismatch; Option[String|Int] ――(right side reduced from) - FoundReqVsImplicit.vecInt.Head[Int] + FoundReqVsImplicit.vecInt.Head val x: vecInt.Head = ??? : Option[String] ^ \ No newline at end of file diff --git a/core/src/test/resources/splain/plugin/VTypeDetailSpec/__direct/check b/core/src/test/resources/splain/plugin/VTypeDetailSpec/__direct/check index b5d49ff..0956114 100644 --- a/core/src/test/resources/splain/plugin/VTypeDetailSpec/__direct/check +++ b/core/src/test/resources/splain/plugin/VTypeDetailSpec/__direct/check @@ -76,3 +76,21 @@ newSource1.scala:16: error: implicit error; ――(defined at newSource1.scala:8:13) wrongf(new A) ^ +newSource1.scala:5: error: implicit error; +!I e: String :: Int :: Boolean + implicitly[K] + ^ +newSource1.scala:7: error: type mismatch; + String("abc")|String :: Int :: Boolean + def v: K = "abc" + ^ +newSource1.scala:5: error: implicit error; +!I e: String :: Int :: Boolean (reduced from) { Test.K } + implicitly[K] + ^ +newSource1.scala:7: error: type mismatch; + String("abc")|String :: Int :: Boolean + ――(right side reduced from) + Test.K + def v: K = "abc" + ^ diff --git a/core/src/test/scala/splain/plugin/VTypeDetailSpec.scala b/core/src/test/scala/splain/plugin/VTypeDetailSpec.scala index 03a9d72..47c7aa2 100644 --- a/core/src/test/scala/splain/plugin/VTypeDetailSpec.scala +++ b/core/src/test/scala/splain/plugin/VTypeDetailSpec.scala @@ -25,6 +25,18 @@ class VTypeDetailSpec extends SpecBase.Direct { } """ + final val reduceToInfix = + """ + object Test { + trait ::[A, B] + + type K = String :: Int :: Boolean + implicitly[K] + + def v: K = "abc" + } + """ + describe("#113") { check(wrongContexts, profile = "-P:splain:Vtype-detail:1", numberOfErrors = 2) @@ -40,4 +52,11 @@ class VTypeDetailSpec extends SpecBase.Direct { check(wrongContexts, profile = "-P:splain:Vtype-detail:6", numberOfErrors = 2) } + describe("#119") { + + check(reduceToInfix, profile = "-P:splain:Vtype-detail:3", numberOfErrors = 2) + + check(reduceToInfix, profile = "-P:splain:Vtype-detail:4", numberOfErrors = 2) + } + } diff --git a/testing/acceptance/src/test/resources/splain/builtin/BasicSpec/__direct/check b/testing/acceptance/src/test/resources/splain/builtin/BasicSpec/__direct/check index 96433ce..df600d5 100644 --- a/testing/acceptance/src/test/resources/splain/builtin/BasicSpec/__direct/check +++ b/testing/acceptance/src/test/resources/splain/builtin/BasicSpec/__direct/check @@ -172,15 +172,7 @@ f invalid because newSource1.scala:11: error: implicit error; !I e: splain.acceptance.builtin.StaticBasicSpec.DeepHole.C1[ - splain.acceptance.builtin.StaticBasicSpec.DeepHole.T3[ - splain.acceptance.builtin.StaticBasicSpec.DeepHole.T1[List[String], ?], - splain.acceptance.builtin.StaticBasicSpec.DeepHole.T2[ - splain.acceptance.builtin.StaticBasicSpec.DeepHole.Id, - splain.acceptance.builtin.StaticBasicSpec.DeepHole.C4, - ? - ], - ? - ] + [Z]splain.acceptance.builtin.StaticBasicSpec.DeepHole.C2[splain.acceptance.builtin.StaticBasicSpec.DeepHole.T1,splain.acceptance.builtin.StaticBasicSpec.DeepHole.T2,Z] ] implicitly[C1[T3]] ^ From a3942e628908cb9628aa77b18a886e70b887486e Mon Sep 17 00:00:00 2001 From: peng Date: Tue, 21 Nov 2023 02:42:19 -0500 Subject: [PATCH 2/4] dependency upgrade --- build.gradle.kts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index c370aad..b58cfc7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,7 +12,7 @@ buildscript { } dependencies { - classpath("ch.epfl.scala:gradle-bloop_2.12:1.6.1") // suffix is always 2.12, weird + classpath("ch.epfl.scala:gradle-bloop_2.12:1.6.2") // suffix is always 2.12, weird } } @@ -33,9 +33,9 @@ plugins { `maven-publish` id("io.github.gradle-nexus.publish-plugin") version "1.3.0" - id("com.github.ben-manes.versions") version "0.49.0" + id("com.github.ben-manes.versions") version "0.50.0" - id("io.github.cosmicsilence.scalafix") version "0.1.14" + id("io.github.cosmicsilence.scalafix") version "0.1.15" } val sonatypeApiUser = providers.gradleProperty("sonatypeApiUser") @@ -144,7 +144,7 @@ allprojects { val scalaTestV = "3.2.11" testFixturesApi("org.scalatest:scalatest_${vs.scalaBinaryV}:${scalaTestV}") - testImplementation("org.junit.jupiter:junit-jupiter:5.10.0") + testImplementation("org.junit.jupiter:junit-jupiter:5.10.1") testRuntimeOnly("co.helmethair:scalatest-junit-runner:0.2.0") } From 808740ec69f192835bb38a9bef2a5d66f6f39485 Mon Sep 17 00:00:00 2001 From: peng Date: Tue, 21 Nov 2023 02:59:34 -0500 Subject: [PATCH 3/4] oops, revert scalafix for Java compatibility --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index b58cfc7..1b8b331 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -35,7 +35,7 @@ plugins { id("com.github.ben-manes.versions") version "0.50.0" - id("io.github.cosmicsilence.scalafix") version "0.1.15" + id("io.github.cosmicsilence.scalafix") version "0.1.14" } val sonatypeApiUser = providers.gradleProperty("sonatypeApiUser") From 6b73ae0ec7a2e4f7a68616df3b8cb5fbb883ec52 Mon Sep 17 00:00:00 2001 From: peng Date: Tue, 21 Nov 2023 13:46:10 -0500 Subject: [PATCH 4/4] dealias_normal moved to TypeView --- .../splain/SplainFormattingExtension.scala | 15 +-------------- .../latest/splain/TyperCompatViews.scala | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/core/src/main/scala-2.13.7+/latest/splain/SplainFormattingExtension.scala b/core/src/main/scala-2.13.7+/latest/splain/SplainFormattingExtension.scala index 3e81db6..b563c36 100644 --- a/core/src/main/scala-2.13.7+/latest/splain/SplainFormattingExtension.scala +++ b/core/src/main/scala-2.13.7+/latest/splain/SplainFormattingExtension.scala @@ -393,20 +393,7 @@ trait SplainFormattingExtension extends typechecker.splain.SplainFormatting with // new implementation is idempotent and won't lose information override def dealias(tpe: Type): Type = { - if (isAux(tpe)) tpe - else { - val result = tpe.dealias.normalize - result match { - case p: PolyType => - val target = dealias(p.resultType) - val _p = p.copy( - resultType = target - ) - _p - case _ => - result - } - } + TypeView(tpe).dealias_normal } case class FormattedIndex( diff --git a/core/src/main/scala-2.13.7+/latest/splain/TyperCompatViews.scala b/core/src/main/scala-2.13.7+/latest/splain/TyperCompatViews.scala index cc7705f..82508e9 100644 --- a/core/src/main/scala-2.13.7+/latest/splain/TyperCompatViews.scala +++ b/core/src/main/scala-2.13.7+/latest/splain/TyperCompatViews.scala @@ -20,6 +20,24 @@ trait TyperCompatViews { self } + lazy val dealias_normal: Type = { + + if (isAux(self)) self + else { + val result = self.dealias.normalize + result match { + case p: PolyType => + val target = TypeView(p.resultType).dealias_normal + val _p = p.copy( + resultType = target + ) + _p + case _ => + result + } + } + } + lazy val definingSymbol: Symbol = { self match {