__init__ is not strictly necessary #11

Closed
opened 2021-09-20 11:50:26 +08:00 by sb10q · 2 comments
Owner
class B:
    pass

results in:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "class def must have __init__ method defined"', nac3standalone/src/main.rs:60:11

but should be equivalent to:

class B:
    def __init__(self):
        1 # work around issue 10

which compiles.

``` class B: pass ``` results in: ``` thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "class def must have __init__ method defined"', nac3standalone/src/main.rs:60:11 ``` but should be equivalent to: ``` class B: def __init__(self): 1 # work around issue 10 ``` which compiles.
Contributor

Yes, __init__ is not required for classes with no fields. Simple to fix later.

Yes, `__init__` is not required for classes with no fields. Simple to fix later.
Collaborator

In top level, this should be fixed with field initialization check added in the latest commit. I think the codegen needs to be modified at around here to fully support this.

Currently this

class C:
    pass

def run() -> int32:
    c = C()
    return 0

gives:

thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', nac3core/src/codegen/expr.rs:129:41
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Got an error: called `Option::unwrap()` on a `None` value
thread 'main' panicked at 'tasks panicked', nac3core/src/codegen/mod.rs:150:13
In top level, this should be fixed with field initialization check added in the latest commit. I think the codegen needs to be modified at around [here](https://git.m-labs.hk/M-Labs/nac3/src/branch/standalone_composer/nac3core/src/codegen/expr.rs#L122-L129) to fully support this. Currently this ```python class C: pass def run() -> int32: c = C() return 0 ``` gives: ``` thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', nac3core/src/codegen/expr.rs:129:41 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace Got an error: called `Option::unwrap()` on a `None` value thread 'main' panicked at 'tasks panicked', nac3core/src/codegen/mod.rs:150:13 ```
pca006132 referenced this issue from a commit 2021-09-21 11:30:08 +08:00
Sign in to join this conversation.
No Milestone
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#11
No description provided.