mirror of
https://github.com/AdaCore/langkit.git
synced 2026-02-12 12:28:12 -08:00
RA22-015: handle @property annotation on FunDecls
This commit is contained in:
committed by
Pierre-Marie de Rodat
parent
e085739b5f
commit
1140c23651
@@ -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):
|
||||
|
||||
3
testsuite/tests/contrib/lkt_semantic/property/test.lkt
Normal file
3
testsuite/tests/contrib/lkt_semantic/property/test.lkt
Normal file
@@ -0,0 +1,3 @@
|
||||
@property fun test(): Int = 12
|
||||
|
||||
a : Int = test
|
||||
17
testsuite/tests/contrib/lkt_semantic/property/test.out
Normal file
17
testsuite/tests/contrib/lkt_semantic/property/test.out
Normal 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>
|
||||
|
||||
1
testsuite/tests/contrib/lkt_semantic/property/test.yaml
Normal file
1
testsuite/tests/contrib/lkt_semantic/property/test.yaml
Normal file
@@ -0,0 +1 @@
|
||||
driver: lkt
|
||||
Reference in New Issue
Block a user