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

Unable to access the parameters of super class reactor #2397

Open
DNDEMoto opened this issue Aug 7, 2024 · 2 comments
Open

Unable to access the parameters of super class reactor #2397

DNDEMoto opened this issue Aug 7, 2024 · 2 comments
Labels
bug Something isn't working python Related to the Python target
Milestone

Comments

@DNDEMoto
Copy link

DNDEMoto commented Aug 7, 2024

Parameters of the superclass cannot be accessed in the sub class reactor's top-level statement.
For example, the following example uses it as an argument of timer.

target Python;
# super class
reactor GeneralController(control_period = 100 ms) {
    reaction(startup) {=
        print(f"hello")
    =}
}

reactor PIController2 extends GeneralController {
    # error , Accessing super class's parameters in reactor
    timer t(0, self.control_period) # with self
    reaction(startup) {=
        print(f"hello")
    =}
}
reactor PIController3 extends GeneralController {
    # error , Accessing super class's parameters in reactor
    timer t(0, control_period) # without self
    reaction(startup) {=
        print(f"hello")
    =}
}

Errors provided by lfc are as follows

$ lfc src/issueXXXX_constructor.lf 
lfc: error: Couldn't resolve reference to Parameter 'self'.
 --> src/issueXXXX_constructor.lf:17:16
   |
16 | reactor PIController2 extends GeneralController {
17 |     timer t(0, self.control_period)
   |                ^^^^ Couldn't resolve reference to Parameter 'self'.
   |
18 |     reaction(startup) {=

lfc: error: Invalid time.
 --> src/issueXXXX_constructor.lf:17:16
   |
16 | reactor PIController2 extends GeneralController {
17 |     timer t(0, self.control_period)
   |                ^^^^ Invalid time.
   |
18 |     reaction(startup) {=

lfc: error: mismatched input '.' expecting ')'
 --> src/issueXXXX_constructor.lf:17:20
   |
16 | reactor PIController2 extends GeneralController {
17 |     timer t(0, self.control_period)
   |                    ^ mismatched input '.' expecting ')'
   |
18 |     reaction(startup) {=

lfc: error: no viable alternative at input ')'
 --> src/issueXXXX_constructor.lf:17:21
   |
16 | reactor PIController2 extends GeneralController {
17 |     timer t(0, self.control_period)
   |                     ^^^^^^^^^^^^^^ no viable alternative at input ')'
   |
18 |     reaction(startup) {=

lfc: error: Couldn't resolve reference to Parameter 'control_period'.
 --> src/issueXXXX_constructor.lf:24:16
   |
23 | reactor PIController3 extends GeneralController {
24 |     timer t(0, control_period)
   |                ^^^^^^^^^^^^^^ Couldn't resolve reference to Parameter 'control_period'.
   |
25 |     reaction(startup) {=

lfc: fatal error: Aborting due to 5 previous errors.

This problem does not occur for access within a reaction.

target Python;
# super class
reactor GeneralController(control_period = 100 ms) {
    reaction(startup) {=
        print(f"hello GenCtr:{self.control_period}")
    =}
}

# no error: Accessing super class's parameters in reaction
reactor PIController1 extends GeneralController {
    reaction(startup) {=
        print(f"hello Ctr1  :{self.control_period}")
    =}
}

This code can be executed without error

@cmnrd cmnrd added bug Something isn't working python Related to the Python target labels Aug 8, 2024
@lhstrh
Copy link
Member

lhstrh commented Aug 8, 2024

@cmnrd and @edwardalee, this looks like it should be valid code:

reactor PIController3 extends GeneralController {
    # error , Accessing super class's parameters in reactor
    timer t(0, control_period) # without self
    reaction(startup) {=
        print(f"hello")
    =}
}

I suspect that the C target has the same problem.

@edwardalee
Copy link
Collaborator

Yes, there should be no self.

@lhstrh lhstrh added this to the 0.10.0 milestone Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python Related to the Python target
Projects
None yet
Development

No branches or pull requests

4 participants