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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading