Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fields innaccessible in children classes #431

Closed
JSAbrahams opened this issue Jan 3, 2023 · 1 comment
Closed

Fields innaccessible in children classes #431

JSAbrahams opened this issue Jan 3, 2023 · 1 comment
Assignees
Labels
bug: check Something in the type check module isn't working (as intended)

Comments

@JSAbrahams
Copy link
Owner

Description of Bug

Certain fields are undefined when accessing children of classes.

How to Reproduce

type.mamba:

class MyGeneric: String
class MyType(def some_field: String)

type SomeState: MyClass when self.private_field > 2
type OtherState: MyClass when
    self.private_field  > 10
    self.private_field  < 200
    self.required_field < 50

type SuperInterface
    def bar: Int

type MyInterface: SuperInterface
    def required_field: Int
    def higher_order(self) -> int

# some class
class MyClass(def my_field: Int, other_field: String := "Hello"): MyType(other_field), MyInterface
    def required_field: Int := 100
    def private_field: Int := 20

    def fun_a(self: SomeState) => self.some_field := "my field is {self.required_field}"
    def fun_b(self) => print("this function is private: {self.private_field}!")

    def some_higher_order(self, fun: Int -> Int) -> Int => return fun(self.my_field)
    def higher_order(self) -> Int => return self.some_higher_order(\x: Int => x * 2)

Gives the following errors:

Error: Cannot infer type within call property. Expected a `self`.private_field, was Int
 ──→ types.mamba:4:30
   4 | type SomeState: MyClass when self.private_field > 2
                                    ^^^^^^^^^^^^^^^^^^

We expect an Int, but MyInterface does not define private_field
 ──→ types.mamba:4:30
   4 | type SomeState: MyClass when self.private_field > 2
                                    ^^^^^^^^^^^^^^^^^^
     └─→ In call property
       4 | type SomeState: MyClass when self.private_field > 2
                           ^^^^^^^

We expect a String, but MyInterface does not define some_field
 ──→ types.mamba:22:35
  22 |     def fun_a(self: SomeState) => self.some_field := "my field is {self.required_field}"
                                         ^^^^^^^^^^^^^^^
     └─→ In call property
      22 |     def fun_a(self: SomeState) => self.some_field := "my field is {self.required_field}"
                                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Cause

I expect that this is because the Context is not being properly created.
Was noted in #416
However, because this is most likely an issue with the Context, will not solve there but created an issue.
Perhaps because the check stage now works more properly we run into issues here.

@JSAbrahams JSAbrahams added the bug: check Something in the type check module isn't working (as intended) label Jan 3, 2023
@JSAbrahams JSAbrahams added this to the v0.3.7 | Type alias milestone Jan 3, 2023
@JSAbrahams JSAbrahams self-assigned this Jan 3, 2023
@JSAbrahams JSAbrahams changed the title When self in funarg is not own class, fields innaccessible Fields innaccessible in children classes Jan 3, 2023
@JSAbrahams
Copy link
Owner Author

Error was elsewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: check Something in the type check module isn't working (as intended)
Projects
None yet
Development

No branches or pull requests

1 participant