mirror of
https://github.com/fluencelabs/aqua.git
synced 2025-04-25 06:52:13 +00:00
fix(compiler): Fix incorrect service method renaming [fixes LNG-199] (#757)
* Rename only arrows, not service calls * Add tests * Fix comment
This commit is contained in:
parent
c73a98b7a0
commit
e22fff7c8a
@ -6,6 +6,7 @@ import aqua.raw.ops.*
|
||||
import aqua.raw.value.{ApplyPropertyRaw, FunctorRaw, IntoFieldRaw, IntoIndexRaw, LiteralRaw, VarRaw}
|
||||
import aqua.types.*
|
||||
import cats.syntax.show.*
|
||||
import cats.syntax.option.*
|
||||
import cats.data.{Chain, NonEmptyList, NonEmptyMap}
|
||||
import org.scalatest.flatspec.AnyFlatSpec
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
@ -1261,6 +1262,113 @@ class ArrowInlinerSpec extends AnyFlatSpec with Matchers {
|
||||
model.equalsOrShowDiff(expected) shouldEqual true
|
||||
}
|
||||
|
||||
/**
|
||||
* service Test("test-service"):
|
||||
* method(method: string) -> string
|
||||
*
|
||||
* func test(method: string) -> string:
|
||||
* res <- Test.method(method)
|
||||
* <- res
|
||||
*
|
||||
* func main():
|
||||
* method = "method"
|
||||
* test(method)
|
||||
*/
|
||||
"arrow inliner" should "not rename service call [bug LNG-199]" in {
|
||||
val testName = "test"
|
||||
val argMethodName = "method"
|
||||
val serviceName = "Test"
|
||||
val serviceId = LiteralRaw("test-service", LiteralType.string)
|
||||
val res = VarRaw("res", ScalarType.string)
|
||||
|
||||
val testType = ArrowType(
|
||||
domain = ProductType.labelled(List(argMethodName -> ScalarType.string)),
|
||||
codomain = ProductType(ScalarType.string :: Nil)
|
||||
)
|
||||
|
||||
val testBody = SeqTag.wrap(
|
||||
CallArrowRawTag
|
||||
.service(
|
||||
serviceId = serviceId,
|
||||
fnName = argMethodName,
|
||||
call = Call(
|
||||
args = VarRaw(argMethodName, ScalarType.string) :: Nil,
|
||||
exportTo = Call.Export(res.name, res.`type`) :: Nil
|
||||
),
|
||||
name = serviceName,
|
||||
arrowType = ArrowType(
|
||||
domain = ProductType.labelled(List(argMethodName -> ScalarType.string)),
|
||||
codomain = ProductType(ScalarType.string :: Nil)
|
||||
)
|
||||
)
|
||||
.leaf,
|
||||
ReturnTag(
|
||||
NonEmptyList.one(res)
|
||||
).leaf
|
||||
)
|
||||
|
||||
val testFunc = FuncArrow(
|
||||
funcName = testName,
|
||||
body = testBody,
|
||||
arrowType = testType,
|
||||
ret = Nil,
|
||||
capturedArrows = Map.empty,
|
||||
capturedValues = Map.empty,
|
||||
capturedTopology = None
|
||||
)
|
||||
|
||||
val mainType = ArrowType(
|
||||
domain = ProductType(Nil),
|
||||
codomain = ProductType(Nil)
|
||||
)
|
||||
|
||||
val mainBody = SeqTag.wrap(
|
||||
AssignmentTag(
|
||||
LiteralRaw.quote(argMethodName),
|
||||
argMethodName
|
||||
).leaf,
|
||||
CallArrowRawTag
|
||||
.func(
|
||||
fnName = testName,
|
||||
call = Call(args = VarRaw(argMethodName, LiteralType.string) :: Nil, Nil)
|
||||
)
|
||||
.leaf
|
||||
)
|
||||
|
||||
val mainFunc = FuncArrow(
|
||||
funcName = "main",
|
||||
body = mainBody,
|
||||
arrowType = ArrowType(ProductType(Nil), ProductType(Nil)),
|
||||
ret = Nil,
|
||||
capturedArrows = Map(testName -> testFunc),
|
||||
capturedValues = Map.empty,
|
||||
capturedTopology = None
|
||||
)
|
||||
|
||||
val model = ArrowInliner
|
||||
.callArrow[InliningState](
|
||||
mainFunc,
|
||||
CallModel(Nil, Nil)
|
||||
)
|
||||
.runA(InliningState())
|
||||
.value
|
||||
|
||||
val expected = MetaModel
|
||||
.CallArrowModel(testName)
|
||||
.wrap(
|
||||
CallServiceModel(
|
||||
serviceId = ValueModel.fromRaw(serviceId),
|
||||
funcName = argMethodName,
|
||||
call = CallModel(
|
||||
args = LiteralModel.quote(argMethodName) :: Nil,
|
||||
exportTo = CallModel.Export(res.name, res.`type`) :: Nil
|
||||
)
|
||||
).leaf
|
||||
)
|
||||
|
||||
model.equalsOrShowDiff(expected) shouldEqual true
|
||||
}
|
||||
|
||||
/*
|
||||
data Prod:
|
||||
value: string
|
||||
|
@ -179,7 +179,11 @@ case class CallArrowRaw(
|
||||
|
||||
override def renameVars(map: Map[String, String]): ValueRaw =
|
||||
copy(
|
||||
name = map.getOrElse(name, name),
|
||||
name = map
|
||||
.get(name)
|
||||
// Rename only if it is **not** a service or ability call, see [bug LNG-199]
|
||||
.filterNot(_ => ability.isDefined)
|
||||
.getOrElse(name),
|
||||
arguments = arguments.map(_.renameVars(map)),
|
||||
serviceId = serviceId.map(_.renameVars(map))
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user