Skip to content

Commit

Permalink
Mark unsafe pieces
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz committed Nov 3, 2024
1 parent 6a9083c commit 0652614
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ def renderAdt(tpe: NodeType) = {
}

val projections = tpe.subtypes.map { nodeType =>
// UNSAFE: inexhaustive match
// format: off
show"""def ${nodeType.tpe.renderProjection}: ${nodeType
.tpe
.render} = this match { case ${nodeType.tpe.asEnumCase.render}(v) => v; case _ => sys.error("no match") }"""
.render} = this match { case ${nodeType.tpe.asEnumCase.render}(v) => v }"""
// format: on
}

Expand Down Expand Up @@ -143,7 +144,7 @@ def renderClass(tpe: NodeType) = {
|${cases.mkString("\n").indentTrim(2)}
|}""".stripMargin
else
// todo replace head with a stricter "only" check?
// UNSAFE: head
show"""$allFields.head match {
|${cases.mkString("\n").indentTrim(2)}
|}""".stripMargin
Expand Down Expand Up @@ -174,6 +175,7 @@ def renderClass(tpe: NodeType) = {
|${cases.mkString("\n").indentTrim(2)}
|}""".stripMargin
else
// UNSAFE: head
show"""$allChildren.head match {
|${cases.mkString("\n").indentTrim(2)}
|}""".stripMargin
Expand All @@ -200,6 +202,7 @@ def renderClass(tpe: NodeType) = {
.render}() => ${fieldType.tpe.render}(node)
|}""".stripMargin
else
// UNSAFE: get
show"""node.children.collectFirst {
| case node @ ${fieldType.tpe.render}() => ${fieldType.tpe.render}(node)
|}.get""".stripMargin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ enum InputNode {
case StringCase(value: String_)
case StructCase(value: Struct)

def asBoolean: Boolean_ = this match { case BooleanCase(v) => v; case _ => sys.error("no match") }
def asList: List_ = this match { case ListCase(v) => v; case _ => sys.error("no match") }
def asNull: Null_ = this match { case NullCase(v) => v; case _ => sys.error("no match") }
def asNumber: Number = this match { case NumberCase(v) => v; case _ => sys.error("no match") }
def asString: String_ = this match { case StringCase(v) => v; case _ => sys.error("no match") }
def asStruct: Struct = this match { case StructCase(v) => v; case _ => sys.error("no match") }
def asBoolean: Boolean_ = this match { case BooleanCase(v) => v }
def asList: List_ = this match { case ListCase(v) => v }
def asNull: Null_ = this match { case NullCase(v) => v }
def asNumber: Number = this match { case NumberCase(v) => v }
def asString: String_ = this match { case StringCase(v) => v }
def asStruct: Struct = this match { case StructCase(v) => v }

def node: Node = this match {
case BooleanCase(value) => value.node
Expand Down

0 comments on commit 0652614

Please sign in to comment.