From a3ce5be10b1c28ac9f71c49330c5b2b410ba7265 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sat, 9 Oct 2021 16:20:49 +0800 Subject: [PATCH] nac3core: fixes #32 and #57 --- nac3artiq/demo.py | 2 +- nac3core/src/toplevel/composer.rs | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/nac3artiq/demo.py b/nac3artiq/demo.py index 458824118..ebcc9c795 100644 --- a/nac3artiq/demo.py +++ b/nac3artiq/demo.py @@ -7,7 +7,7 @@ class Demo: core: Core led: TTLOut - @portable # FIXME: why does it still compile if @portable is removed? + @portable def __init__(self): self.core = Core() self.led = TTLOut(0) diff --git a/nac3core/src/toplevel/composer.rs b/nac3core/src/toplevel/composer.rs index 9a9a20970..e13cb958f 100644 --- a/nac3core/src/toplevel/composer.rs +++ b/nac3core/src/toplevel/composer.rs @@ -419,8 +419,13 @@ impl TopLevelComposer { // we do not push anything to the def list, so we keep track of the index // and then push in the correct order after the for loop let mut class_method_index_offset = 0; + let mut contains_constructor = false; + let init_id = "__init__".into(); for b in body { if let ast::StmtKind::FunctionDef { name: method_name, .. } = &b.node { + if method_name == &init_id { + contains_constructor = true; + } if self.keyword_list.contains(method_name) { return Err("cannot use keyword as a method name".into()); } @@ -484,7 +489,12 @@ impl TopLevelComposer { self.definition_ast_list.push((def, Some(ast))); } - Ok((class_name, DefinitionId(class_def_id), Some(constructor_ty))) + let result_ty = if contains_constructor { + Some(constructor_ty) + } else { + None + }; + Ok((class_name, DefinitionId(class_def_id), result_ty)) } ast::StmtKind::FunctionDef { name, .. } => {