From 303540982337f3af8ffe0f5ef8bbb508c1b0bad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20AMIARD?= Date: Mon, 27 Sep 2021 12:27:52 +0200 Subject: [PATCH] RA22-015: Use match rt. cast+then In SimpleTypeRef.check_correctness_pre. Also add some comments. --- contrib/lkt/language/parser.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/contrib/lkt/language/parser.py b/contrib/lkt/language/parser.py index c2ad66663..1fe184c16 100644 --- a/contrib/lkt/language/parser.py +++ b/contrib/lkt/language/parser.py @@ -2098,11 +2098,17 @@ def designated_type(): @langkit_property(return_type=T.SemanticResult.array) def check_correctness_pre(): + d = Var(Entity.type_name.referenced_decl) + return d.result_ref.then( - lambda d: d.cast(T.TypeDecl).then( - lambda _: No(T.SemanticResult.array), - default_val=Entity.error(S("Invalid type reference")).singleton + lambda d: d.match( + # The type ref references a type decl: return no error + lambda _=T.TypeDecl: No(T.SemanticResult.array), + + # Not a type decl: return an error that the type reference is + # invalid. + lambda _: [Entity.error(S("Invalid type reference"))] ) )