forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Compensate loss of transitivity"
This reverts commit 7c4bd67 See scala#21344 (comment) Fixes scala#21320
- Loading branch information
1 parent
c09154a
commit 58f3407
Showing
3 changed files
with
76 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |