Skip to content

Commit

Permalink
Revert "Compensate loss of transitivity"
Browse files Browse the repository at this point in the history
This reverts commit 7c4bd67
See #21344 (comment)

Fixes #21320

[Cherry-picked 58f3407][modified]
  • Loading branch information
WojciechMazur committed Aug 28, 2024
1 parent cc37466 commit 17e23ce
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,7 @@ trait Implicits:
def disambiguate(alt1: SearchResult, alt2: SearchSuccess) = alt1 match
case alt1: SearchSuccess =>
var diff = compareAlternatives(alt1, alt2, disambiguate = true)
assert(diff <= 0 || isWarnPriorityChangeVersion)
// diff > 0 candidates should already have been eliminated in `rank`
if diff == 0 && alt1.ref =:= alt2.ref then
diff = 1 // See i12951 for a test where this happens
Expand Down
File renamed without changes.
73 changes: 73 additions & 0 deletions tests/pos/i21320b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import scala.deriving.*
import scala.compiletime.*

trait ConfigMonoid[T]:
def zero: T
def orElse(main: T, defaults: T): T

object ConfigMonoid:
given option[T]: ConfigMonoid[Option[T]] = ???

inline def zeroTuple[C <: Tuple]: Tuple =
inline erasedValue[C] match
case _: EmptyTuple => EmptyTuple
case _: (t *: ts) =>
summonInline[ConfigMonoid[t]].zero *: zeroTuple[ts]

inline def valueTuple[C <: Tuple, T](index: Int, main: T, defaults: T): Tuple =
inline erasedValue[C] match
case _: EmptyTuple => EmptyTuple
case _: (t *: ts) =>
def get(v: T) = v.asInstanceOf[Product].productElement(index).asInstanceOf[t]
summonInline[ConfigMonoid[t]].orElse(get(main), get(defaults)) *: valueTuple[ts, T](
index + 1,
main,
defaults
)

inline given derive[T](using m: Mirror.ProductOf[T]): ConfigMonoid[T] =
new ConfigMonoid[T]:
def zero: T = m.fromProduct(zeroTuple[m.MirroredElemTypes])
def orElse(main: T, defaults: T): T = m.fromProduct(valueTuple[m.MirroredElemTypes, T](0, main, defaults))



final case class PublishOptions(
v1: Option[String] = None,
v2: Option[String] = None,
v3: Option[String] = None,
v4: Option[String] = None,
v5: Option[String] = None,
v6: Option[String] = None,
v7: Option[String] = None,
v8: Option[String] = None,
v9: Option[String] = None,
ci: PublishContextualOptions = PublishContextualOptions(),
)
object PublishOptions:
implicit val monoid: ConfigMonoid[PublishOptions] = ConfigMonoid.derive

final case class PublishContextualOptions(
v1: Option[String] = None,
v2: Option[String] = None,
v3: Option[String] = None,
v4: Option[String] = None,
v5: Option[String] = None,
v6: Option[String] = None,
v7: Option[String] = None,
v8: Option[String] = None,
v9: Option[String] = None,
v10: Option[String] = None,
v11: Option[String] = None,
v12: Option[String] = None,
v13: Option[String] = None,
v14: Option[String] = None,
v15: Option[String] = None,
v16: Option[String] = None,
v17: Option[String] = None,
v18: Option[String] = None,
v19: Option[String] = None,
v20: Option[String] = None
)
object PublishContextualOptions:
implicit val monoid: ConfigMonoid[PublishContextualOptions] = ConfigMonoid.derive // was crash

0 comments on commit 17e23ce

Please sign in to comment.