簡體   English   中英

Slick 中的 DBIOAction[_, NoStream, Read with Write with Read]

[英]DBIOAction[_, NoStream, Read with Write with Read] in Slick

假設我有以下操作,首先執行讀取操作,然后更新字段。

action1: DBIOAction[Any, NoStream, Read with Write]

action2對同一張表進行另一次讀取操作。 要按順序執行這三個操作,我執行以下操作:

val action3 = action1 andThen action2

所以我認為 output 應該是格式。

action3: DBIOAction[Any, NoStream, Read with Write with Read]

但是當我看到 output 又是這樣的形式時:

DBIOAction[Any, NoStream, Read with Write]

事實上,在方法的簽名中,我寫了DBIOAction[Any, NoStream, Read with Write with Read]但 IntelliJ 沒有抱怨。 這似乎不正確。 我做錯了嗎?

Read with Write with ReadRead with Write大部分是同一類型:

implicitly[Read with Write with Read =:= Read with Write] // compiles
implicitly[Read with Write =:= Read with Write with Read] // compiles
implicitly[Write with Read =:= Read with Write] // compiles
implicitly[Read with Write =:= Write with Read] // compiles

盡管根據規范,它們似乎不等價(≡):

兩個復合類型是等價的,如果它們的組件的序列是成對等價的,並且以相同的順序出現,並且它們的細化是等價的。

查看編譯器:

https://github.com/scala/scala/pull/3981

RefinedType#normalize負責將嵌套的復合類型展平為平面表示。

=:=期間對類型進行規范化以尋找成功的結果。

這意味着((A with B) with C) =:= (A with B with C)

https://github.com/retronym/scala/blob/a9182fbeaf018c1aa0f88f0aee7b921383b746f2/src/reflect/scala/reflect/internal/Types.scala#L1601-L1619

private def normalizeImpl = {
  // TODO see comments around def intersectionType and def merge
  // SI-8575 The dealias is needed here to keep subtyping transitive, example in run/t8575b.scala
  def flatten(tps: List[Type]): List[Type] = {
    def dealiasRefinement(tp: Type) = if (tp.dealias.isInstanceOf[RefinedType]) tp.dealias else tp
    tps map dealiasRefinement flatMap {
      case RefinedType(parents, ds) if ds.isEmpty => flatten(parents)
      case tp => List(tp)
    }
  }
  val flattened = flatten(parents).distinct
  if (decls.isEmpty && hasLength(flattened, 1)) {
    flattened.head
  } else if (flattened != parents) {
    refinedType(flattened, if (typeSymbol eq NoSymbol) NoSymbol else typeSymbol.owner, decls, NoPosition)
  } else if (isHigherKinded) {
    etaExpand
  } else super.normalize
}

注意flatten(...).distinct的用法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM