mirror of
https://github.com/fluencelabs/aqua.git
synced 2024-12-04 14:40:17 +00:00
fix(compiler): Redeclare imports [LNG-344] (#1109)
This commit is contained in:
parent
cc69e696dc
commit
8f06ac1cba
@ -1,39 +1,8 @@
|
||||
aqua A
|
||||
aqua Main
|
||||
|
||||
export streamTry, streamFor
|
||||
import someFunc from "import.aqua"
|
||||
|
||||
service FailureSrv("failure"):
|
||||
fail(msg: string)
|
||||
export someFunc
|
||||
|
||||
func streamTry() -> i8:
|
||||
on HOST_PEER_ID:
|
||||
try:
|
||||
stream: *i8
|
||||
anotherStream = stream
|
||||
stream <<- 1
|
||||
anotherStream <<- 1
|
||||
FailureSrv.fail("try")
|
||||
catch e:
|
||||
stream = *[88,88,88]
|
||||
stream <<- 2
|
||||
FailureSrv.fail("catch")
|
||||
otherwise:
|
||||
stream: *i8
|
||||
stream <<- 3
|
||||
|
||||
stream: *i8
|
||||
stream <<- 4
|
||||
|
||||
<- stream!
|
||||
|
||||
service StreamService("test-service"):
|
||||
store(numbers: []u32, n: u32)
|
||||
|
||||
func callService(stream: *u32, n: u32):
|
||||
stream <<- 1
|
||||
StreamService.store(stream, n)
|
||||
|
||||
func streamFor():
|
||||
arr = [1,2,3,4,5]
|
||||
for a <- arr:
|
||||
callService(*[], a)
|
||||
func a() -> string:
|
||||
<- "srrt"
|
||||
|
@ -1,6 +1,10 @@
|
||||
service GetStr("multiret-test"):
|
||||
retStr(s: *string, a: *string)
|
||||
aqua Import declares someFunc
|
||||
|
||||
service GetStr("multiret-test"):
|
||||
retStr(s: []string, a: []string)
|
||||
|
||||
func someFunc() -> string:
|
||||
<- "some func call"
|
||||
|
||||
func foo_wrapper():
|
||||
GetStr.retStr(nil, nil)
|
||||
|
4
integration-tests/aqua/examples/redeclare/import.aqua
Normal file
4
integration-tests/aqua/examples/redeclare/import.aqua
Normal file
@ -0,0 +1,4 @@
|
||||
aqua Import declares someFunc
|
||||
|
||||
func someFunc() -> string:
|
||||
<- "some func"
|
3
integration-tests/aqua/examples/redeclare/redeclare.aqua
Normal file
3
integration-tests/aqua/examples/redeclare/redeclare.aqua
Normal file
@ -0,0 +1,3 @@
|
||||
aqua Redeclare declares someFunc
|
||||
|
||||
import someFunc from "import.aqua"
|
@ -0,0 +1,5 @@
|
||||
aqua UseDeclare declares someFunc
|
||||
|
||||
import someFunc from "redeclare.aqua"
|
||||
|
||||
export someFunc
|
@ -11,6 +11,7 @@ import cats.kernel.Semigroup
|
||||
import cats.syntax.foldable.*
|
||||
import cats.syntax.functor.*
|
||||
import cats.syntax.option.*
|
||||
import cats.syntax.semigroup.*
|
||||
import cats.syntax.validated.*
|
||||
import cats.{Comonad, Monoid}
|
||||
|
||||
@ -30,31 +31,32 @@ class ModuleSem[S[_]: Comonad, C: Picker](expr: ModuleExpr[S])(using
|
||||
name.value,
|
||||
shouldDeclare
|
||||
),
|
||||
(ctx, _) =>
|
||||
(ctx, initCtx) =>
|
||||
val sumCtx = ctx |+| initCtx
|
||||
// When file is handled, check that all the declarations exists
|
||||
if (declareAll.nonEmpty)
|
||||
ctx.setModule(name.value, declares = ctx.all).validNec
|
||||
else
|
||||
val allDeclared = ctx.all ++ initCtx.all
|
||||
sumCtx.setModule(name.value, declares = allDeclared).validNec
|
||||
else {
|
||||
// summarize contexts to allow redeclaration of imports
|
||||
(
|
||||
declareNames.fproductLeft(_.value) ::: declareCustom.fproductLeft(_.value)
|
||||
).map { case (n, t) =>
|
||||
ctx
|
||||
.pick(n, None, ctx.module.nonEmpty)
|
||||
sumCtx
|
||||
.pick(n, None, sumCtx.module.nonEmpty)
|
||||
.toValidNec(
|
||||
error(
|
||||
t,
|
||||
s"`$n` is expected to be declared, but declaration is not found in the file"
|
||||
)
|
||||
)
|
||||
.void
|
||||
).void
|
||||
}.combineAll.as {
|
||||
val tokens = declareNames.map(n => n.value -> n) ++ declareCustom.map(a => a.value -> a)
|
||||
val ctxWithDeclaresLoc = ctx.addOccurences(tokens)
|
||||
val ctxWithDeclaresLoc = sumCtx.addOccurences(tokens)
|
||||
// TODO: why module name and declares is lost? where is it lost?
|
||||
ctxWithDeclaresLoc.setModule(name.value, declares = shouldDeclare)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
)
|
||||
|
||||
word.value.fold(
|
||||
|
@ -729,7 +729,7 @@ class TypesInterpreter[S[_], X](using
|
||||
report
|
||||
.error(
|
||||
token,
|
||||
s"Name `${name}` was already defined here"
|
||||
s"Name `$name` was already defined here"
|
||||
)
|
||||
.as(ifDefined)
|
||||
case None => ifNotDefined
|
||||
|
Loading…
Reference in New Issue
Block a user