Skip to content

Commit

Permalink
RA22-015: Fix resolution of calls to non statically resolvable fns
Browse files Browse the repository at this point in the history
  • Loading branch information
raph-amiard committed Sep 30, 2021
1 parent da65c32 commit f8264d9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
17 changes: 17 additions & 0 deletions contrib/lkt/language/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2579,6 +2579,23 @@ def called_decl():
),
# If not a generic decl, fall back on the initially found decl
default_val=called_decl
)._.match(
# Here, if we found a declaration but it's not one of the
# statically callable declarations (FunDecl or TypeDecl), we
# return nothing, even though we might be able to statically
# determine a declaration, like in the example below::
#
# val a: (Int) -> Int = null
# val b: Int = a(12)
#
# That's because in language semantic terms, the actual called
# function is determined dynamically in the above case.
#
# TODO: Maybe introduce a base class for statically callable
# declarations, so we don't have to do this ugly match.
lambda t=TypeDecl: t,
lambda f=FunDecl: f,
lambda _: No(T.Decl.entity)
)

@langkit_property()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Call a non static declaration

val a: (Int) -> Int = null
val b: Int = a(12)
26 changes: 26 additions & 0 deletions testsuite/tests/contrib/lkt_semantic/call_non_static_decl/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Resolving test.lkt
==================
Id <RefId "Int" test.lkt:3:9-3:12>
references <StructDecl prelude: "Int">

Id <RefId "Int" test.lkt:3:17-3:20>
references <StructDecl prelude: "Int">

Expr <NullLit test.lkt:3:23-3:27>
has type <FunctionType prelude: "(Int) -> Int">

Id <RefId "Int" test.lkt:4:8-4:11>
references <StructDecl prelude: "Int">

Id <RefId "a" test.lkt:4:14-4:15>
references <ValDecl "a" test.lkt:3:1-3:27>

Expr <RefId "a" test.lkt:4:14-4:15>
has type <FunctionType prelude: "(Int) -> Int">

Expr <NumLit test.lkt:4:16-4:18>
has type <StructDecl prelude: "Int">

Expr <CallExpr test.lkt:4:14-4:19>
has type <StructDecl prelude: "Int">

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
driver: lkt

0 comments on commit f8264d9

Please sign in to comment.