Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): Runtime error on compilation exported functions with top types [fixes LNG-218] #822

Merged
merged 12 commits into from
Aug 9, 2023
25 changes: 19 additions & 6 deletions backend/ts/src/main/scala/aqua/backend/ts/TypeScriptCommon.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,26 @@ object TypeScriptCommon {
s"{ ${st.fields.map(typeToTs).toNel.map(kv => kv._1 + ": " + kv._2 + ";").toList.mkString(" ")} }"
case st: AbilityType =>
s"{ ${st.fields.map(typeToTs).toNel.map(kv => kv._1 + ": " + kv._2 + ";").toList.mkString(" ")} }"
case st: ScalarType if ScalarType.number(st) => "number"
case ScalarType.bool => "boolean"
case ScalarType.string => "string"
case lt: LiteralType if lt.oneOf.exists(ScalarType.number) => "number"
case lt: LiteralType if lt.oneOf(ScalarType.bool) => "boolean"
case lt: LiteralType if lt.oneOf(ScalarType.string) => "string"
case st: ScalarType => st match {
case st: ScalarType if ScalarType.number(st) => "number"
case ScalarType.bool => "boolean"
case ScalarType.string => "string"
// unreachable
case _ => "any"
}
case lt: LiteralType => lt match {
case lt: LiteralType if lt.oneOf.exists(ScalarType.number) => "number"
case lt: LiteralType if lt.oneOf(ScalarType.bool) => "boolean"
case lt: LiteralType if lt.oneOf(ScalarType.string) => "string"
// unreachable
case _ => "any"
}
case at: ArrowType => fnDef(at)
case TopType => "any"
case BottomType => "nothing"

// impossible. Made to avoid compilation warning
case t: CanonStreamType => "any"
}

// TODO: handle cases if there is already peer_ or config_ variable defined
Expand Down
12 changes: 12 additions & 0 deletions integration-tests/aqua/examples/topbottom.aqua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
aqua TopBottom

export S, topBottom

-- this file should just compile

service S(""):
top(t: ⊤) -> ⊤
bottom(b: ⊥) -> ⊥

func topBottom(t: ⊤, b: ⊥) -> ⊤, ⊥:
<- S.top(t), S.bottom(b)
Loading