Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/agents/type-system-agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
5. Run tests locally:

```bash
pytest -n auto jac/jaclang/compiler/passes/main/tests/test_checker_pass.py -v

cd jac && pytest -k test_<feature> -v

```

6. Add a one-line entry to `docs/docs/communityhub/release_notes/jaclang.md` under the Unreleased section (optionally under “Type Checking Enhancements”).
Expand Down
14 changes: 14 additions & 0 deletions jac/jaclang/compiler/type_system/type_evaluator.jac
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ obj PrefetchedTypes {
has none_type_class: TypeBase | None = None;
has object_class: TypeBase | None = None;
has type_class: TypeBase | None = None;
has property_class: TypeBase | None = None;
has union_type_class: TypeBase | None = None;
has awaitable_class: TypeBase | None = None;
has function_class: TypeBase | None = None;
Expand Down Expand Up @@ -198,6 +199,7 @@ class TypeEvaluator {
self.prefetch.none_type_class = get_types_type("NoneType");
self.prefetch.object_class = get_builtin_type("object");
self.prefetch.type_class = get_builtin_type("type");
self.prefetch.property_class = get_builtin_type("property");
self.prefetch.union_type_class = get_types_type("UnionType");
# self.prefetch.awaitable_class =
# self.prefetch.function_class =
Expand Down Expand Up @@ -983,6 +985,18 @@ class TypeEvaluator {
if isinstance(expr_type, types.FunctionType) {
expr_type = expr_type.specialize(base_type);
}
# If the memeber is a property the type will be the return value of the property
node_ = symbol.decl.name_of;
if isinstance(node_, uni.Ability) {
assert isinstance(expr_type, types.FunctionType);
for decor in (node_.decorators or []) {
decor_type = self.get_type_of_expression(decor);
if isinstance(decor_type, types.ClassType)
and decor_type.shared == self.prefetch.property_class.shared {
expr_type = expr_type.return_type;
}
}
}
return expr_type;
}
return types.UnknownType();
Expand Down
17 changes: 17 additions & 0 deletions jac/tests/compiler/passes/main/fixtures/checker_property.jac
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import from typing { Any }

obj Foo {
@property
def bar() -> str {
return "Hello, World!";
}

def ba() -> int {
return 42;
}
}

with entry {
foo = Foo();
b: str = foo.bar; # <-- Ok (No error)
}
Loading