[wavesplatform/Waves] NODE-753-allow-unions-in-pattern-matching (#1140)

ismagin requested changes on this pull request.

> @@ -14,3 +15,7 @@ case class PredefType(name: String, fields: List[(String, TYPE)]) extends Predef
case class PredefCaseType(name: String, fields: List[(String, TYPE)]) extends PredefBase {
lazy val typeRef = CASETYPEREF(name)
}
+case class UnionType(name: String, types: List[CASETYPEREF], ctx: CompilerContext) extends PredefBase {

1. `ctx` shouldn’t be part of this. `fields` is used in compiler where the context is already available
2. `UnionType` and `UNION` are very similar. maybe this can be 1 type, maybe with `name: Option[String]` ?

> @@ -16,8 +16,8 @@ object CompilerContext {

val empty = CompilerContext(Map.empty, Map.empty, Map.empty, 0)

— def fromEvaluationContext(ctx: EvaluationContext): CompilerContext = {
+ def fromEvaluationContext(ctx: EvaluationContext, types: Map[String, PredefBase]): CompilerContext = {

looks like this is not needed: `types` is always empty around the code :)

> @@ -36,6 +36,7 @@ object Serde {
implicit def dFalse = d.bind[FALSE.type](7)
implicit def dGetter = d.bind[GETTER](8)
implicit def dFunctionCall = d.bind[FUNCTION_CALL](9)
+ implicit def dTypeList = d.bind[TYPELIST](10)

Let’s not rush with new entites until we’re sure about its form.
Maybe, for simplicity, we’ll have seperate declaring section later, where users definte types, unions and functions.

> @@ -55,22 +58,34 @@ object CompilerV1 {
case getter: Expressions.GETTER => compileGetter(ctx, getter)
case fc: Expressions.FUNCTION_CALL => compileFunctionCall(ctx, fc)
case block: Expressions.BLOCK => compileBlock(ctx, block)
+ case Expressions.TBLOCK(_, _, PART.INVALID(start,end,message), _, _) => EitherT.leftT[Coeval, EXPR](s»$message in $start-$end»)

the idea is that such things can be defined statically or just plin upfront, let’s stay away from it until needed

Добавить комментарий