forked from M-Labs/nac3
1
0
Fork 0

nac3core: fixes #32 and #57

This commit is contained in:
pca006132 2021-10-09 16:20:49 +08:00
parent a22552a012
commit a3ce5be10b
2 changed files with 12 additions and 2 deletions

View File

@ -7,7 +7,7 @@ class Demo:
core: Core core: Core
led: TTLOut led: TTLOut
@portable # FIXME: why does it still compile if @portable is removed? @portable
def __init__(self): def __init__(self):
self.core = Core() self.core = Core()
self.led = TTLOut(0) self.led = TTLOut(0)

View File

@ -419,8 +419,13 @@ impl TopLevelComposer {
// we do not push anything to the def list, so we keep track of the index // 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 // and then push in the correct order after the for loop
let mut class_method_index_offset = 0; let mut class_method_index_offset = 0;
let mut contains_constructor = false;
let init_id = "__init__".into();
for b in body { for b in body {
if let ast::StmtKind::FunctionDef { name: method_name, .. } = &b.node { 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) { if self.keyword_list.contains(method_name) {
return Err("cannot use keyword as a method name".into()); return Err("cannot use keyword as a method name".into());
} }
@ -484,7 +489,12 @@ impl TopLevelComposer {
self.definition_ast_list.push((def, Some(ast))); 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, .. } => { ast::StmtKind::FunctionDef { name, .. } => {