From e7e7207b45a9023df924120e2886c635ab999e07 Mon Sep 17 00:00:00 2001 From: Romain Beauxis Date: Tue, 10 Dec 2024 05:14:06 -0600 Subject: [PATCH] Add support for type annotations for optional types with methods. (#4251) --- src/lang/parser.mly | 2 ++ tests/language/typing.liq | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/lang/parser.mly b/src/lang/parser.mly index 520bb222e5..d7401b2966 100644 --- a/src/lang/parser.mly +++ b/src/lang/parser.mly @@ -292,6 +292,8 @@ ty: | LPAR argsty RPAR YIELDS ty { `Arrow ($2,$5) } | LCUR record_ty RCUR { `Record $2 } | ty DOT VAR { `Invoke ($1, $3) } + | ty QUESTION_DOT LCUR record_ty RCUR + { `Method (`Nullable $1, $4) } | ty DOT LCUR record_ty RCUR { `Method ($1, $4) } | ty_source { `Source $1 } diff --git a/tests/language/typing.liq b/tests/language/typing.liq index a467718b4c..cd3dfa217c 100644 --- a/tests/language/typing.liq +++ b/tests/language/typing.liq @@ -209,6 +209,9 @@ def f() = int.{ "✨ name ✨" as foo: float, gni: string } ) + # Nullable type with methods: + (123.{foo="aabb"} : int?.{ foo: string }) + (() : {}) (() : unit.{ }) ({foo=123} : {foo?: int})