From f8264d919880e31a206ae130bc205d195af24e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20AMIARD?= Date: Mon, 27 Sep 2021 15:57:04 +0200 Subject: [PATCH] RA22-015: Fix resolution of calls to non statically resolvable fns --- contrib/lkt/language/parser.py | 17 ++++++++++++ .../call_non_static_decl/test.lkt | 4 +++ .../call_non_static_decl/test.out | 26 +++++++++++++++++++ .../call_non_static_decl/test.yaml | 1 + 4 files changed, 48 insertions(+) create mode 100644 testsuite/tests/contrib/lkt_semantic/call_non_static_decl/test.lkt create mode 100644 testsuite/tests/contrib/lkt_semantic/call_non_static_decl/test.out create mode 100644 testsuite/tests/contrib/lkt_semantic/call_non_static_decl/test.yaml diff --git a/contrib/lkt/language/parser.py b/contrib/lkt/language/parser.py index 2dc5f7fd1..c2ad66663 100644 --- a/contrib/lkt/language/parser.py +++ b/contrib/lkt/language/parser.py @@ -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() diff --git a/testsuite/tests/contrib/lkt_semantic/call_non_static_decl/test.lkt b/testsuite/tests/contrib/lkt_semantic/call_non_static_decl/test.lkt new file mode 100644 index 000000000..2357f0d5b --- /dev/null +++ b/testsuite/tests/contrib/lkt_semantic/call_non_static_decl/test.lkt @@ -0,0 +1,4 @@ +# Call a non static declaration + +val a: (Int) -> Int = null +val b: Int = a(12) diff --git a/testsuite/tests/contrib/lkt_semantic/call_non_static_decl/test.out b/testsuite/tests/contrib/lkt_semantic/call_non_static_decl/test.out new file mode 100644 index 000000000..0ead5764b --- /dev/null +++ b/testsuite/tests/contrib/lkt_semantic/call_non_static_decl/test.out @@ -0,0 +1,26 @@ +Resolving test.lkt +================== +Id + references + +Id + references + +Expr + has type Int"> + +Id + references + +Id + references + +Expr + has type Int"> + +Expr + has type + +Expr + has type + diff --git a/testsuite/tests/contrib/lkt_semantic/call_non_static_decl/test.yaml b/testsuite/tests/contrib/lkt_semantic/call_non_static_decl/test.yaml new file mode 100644 index 000000000..7695167b5 --- /dev/null +++ b/testsuite/tests/contrib/lkt_semantic/call_non_static_decl/test.yaml @@ -0,0 +1 @@ +driver: lkt