Skip to content

Commit

Permalink
fix(compiler): Runtime error on compilation exported functions with t…
Browse files Browse the repository at this point in the history
…op types [fixes LNG-218] (#822)
  • Loading branch information
DieMyst authored Aug 9, 2023
1 parent d263797 commit ef4b014
Show file tree
Hide file tree
Showing 10 changed files with 1,533 additions and 721 deletions.
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
25 changes: 25 additions & 0 deletions integration-tests/aqua/examples/renameVars.aqua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
aqua RenameVars

export rename_s

func append_func(s: *string):
s <<- "ok"

func append(s: string, closure: *string -> ()) -> *string:
status: *string

append_func(status)
closure(status)

<- status

func rename_s() -> []string:
on HOST_PEER_ID:
append_closure = (s: *string):
s <<- "ok"
-- s inside append_func and append_closure
-- are not related to this s and should be
-- renamed to `status` and not `s-<n>`
s = "s"
res <- append(s, append_closure)
<- res
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

0 comments on commit ef4b014

Please sign in to comment.