RA22-015: handle @property annotation on FunDecls

This commit is contained in:
Raphaël AMIARD
2020-06-18 16:07:35 +02:00
committed by Pierre-Marie de Rodat
parent e085739b5f
commit 1140c23651
4 changed files with 44 additions and 13 deletions

View File

@@ -522,6 +522,8 @@ class Decl(LKNode):
"""
)
full_decl = Property(Entity.parent.cast_or_raise(T.FullDecl))
quoted_name = Property(S("`").concat(Self.full_name).concat(S("`")))
env_spec = EnvSpec(add_to_env_kv(Entity.name, Self))
@@ -1803,19 +1805,27 @@ class FunDecl(UserValDecl):
@langkit_property()
def get_type(no_inference=(T.Bool, False)):
ignore(no_inference)
return Self.function_type(
# NOTE: For methods, we don't add the owning type. We consider that
# for the moment the only kind of references to method's function
# types are with the self argument bound (ie. via dot notation).
#
# At some stage we might want to create a notation for a "free
# method", where `self` is not bound, but that doesn't exist yet.
Entity.args.map(
lambda a:
a.decl_type.designated_type.assert_bare.cast(T.TypeDecl)
),
Entity.return_type.designated_type.assert_bare.cast(T.TypeDecl)
).as_bare_entity
return If(
Entity.full_decl.get_annotation('property').is_null,
Self.function_type(
# NOTE: For methods, we don't add the owning type. We consider
# that for the moment the only kind of references to method's
# function types are with the self argument bound (ie. via dot
# notation).
#
# At some stage we might want to create a notation for a "free
# method", where `self` is not bound, but that doesn't exist
# yet.
Entity.args.map(
lambda a:
a.decl_type.designated_type.assert_bare.cast(T.TypeDecl)
),
Entity.return_type.designated_type.assert_bare.cast(T.TypeDecl)
).as_bare_entity,
Entity.return_type.designated_type
)
class EnumLitDecl(UserValDecl):

View File

@@ -0,0 +1,3 @@
@property fun test(): Int = 12
a : Int = test

View File

@@ -0,0 +1,17 @@
Resolving test.lkt
==================
Id <RefId "Int" test.lkt:1:23-1:26>
references <StructDecl "Int" __prelude:1:10-1:23>
Expr <NumLit test.lkt:1:29-1:31>
has type <StructDecl "Int" __prelude:1:10-1:23>
Id <RefId "Int" test.lkt:3:5-3:8>
references <StructDecl "Int" __prelude:1:10-1:23>
Id <RefId "test" test.lkt:3:11-3:15>
references <FunDecl "test" test.lkt:1:11-1:31>
Expr <RefId "test" test.lkt:3:11-3:15>
has type <StructDecl "Int" __prelude:1:10-1:23>

View File

@@ -0,0 +1 @@
driver: lkt