nac3core: top level fix function/methods none return type
This commit is contained in:
parent
98d032b72a
commit
1ae6acc061
|
@ -678,11 +678,10 @@ impl TopLevelComposer {
|
||||||
.collect::<Result<Vec<_>, _>>()?
|
.collect::<Result<Vec<_>, _>>()?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let return_ty = {
|
||||||
|
if let Some(returns) = returns {
|
||||||
let return_ty_annotation = {
|
let return_ty_annotation = {
|
||||||
let return_annotation = returns
|
let return_annotation = returns.as_ref();
|
||||||
.as_ref()
|
|
||||||
.ok_or_else(|| "function return type needed".to_string())?
|
|
||||||
.as_ref();
|
|
||||||
parse_ast_to_type_annotation_kinds(
|
parse_ast_to_type_annotation_kinds(
|
||||||
resolver,
|
resolver,
|
||||||
&temp_def_list,
|
&temp_def_list,
|
||||||
|
@ -710,13 +709,16 @@ impl TopLevelComposer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let return_ty = get_type_from_type_annotation_kinds(
|
get_type_from_type_annotation_kinds(
|
||||||
&temp_def_list,
|
&temp_def_list,
|
||||||
unifier,
|
unifier,
|
||||||
primitives_store,
|
primitives_store,
|
||||||
&return_ty_annotation,
|
&return_ty_annotation,
|
||||||
)?;
|
)?
|
||||||
|
} else {
|
||||||
|
primitives_store.none
|
||||||
|
}
|
||||||
|
};
|
||||||
let function_ty = unifier.add_ty(TypeEnum::TFunc(
|
let function_ty = unifier.add_ty(TypeEnum::TFunc(
|
||||||
FunSignature { args: arg_types, ret: return_ty, vars: function_var_map }
|
FunSignature { args: arg_types, ret: return_ty, vars: function_var_map }
|
||||||
.into(),
|
.into(),
|
||||||
|
@ -883,10 +885,8 @@ impl TopLevelComposer {
|
||||||
|
|
||||||
let ret_type = {
|
let ret_type = {
|
||||||
if name != "__init__" {
|
if name != "__init__" {
|
||||||
let result = returns
|
if let Some(result) = returns {
|
||||||
.as_ref()
|
let result = result.as_ref();
|
||||||
.ok_or_else(|| "method return type annotation needed".to_string())?
|
|
||||||
.as_ref();
|
|
||||||
let annotation = parse_ast_to_type_annotation_kinds(
|
let annotation = parse_ast_to_type_annotation_kinds(
|
||||||
class_resolver,
|
class_resolver,
|
||||||
temp_def_list,
|
temp_def_list,
|
||||||
|
@ -914,6 +914,16 @@ impl TopLevelComposer {
|
||||||
let dummy_return_type = unifier.get_fresh_var().0;
|
let dummy_return_type = unifier.get_fresh_var().0;
|
||||||
type_var_to_concrete_def.insert(dummy_return_type, annotation.clone());
|
type_var_to_concrete_def.insert(dummy_return_type, annotation.clone());
|
||||||
dummy_return_type
|
dummy_return_type
|
||||||
|
} else {
|
||||||
|
// if do not have return annotation, return none
|
||||||
|
// for uniform handling, still use type annoatation
|
||||||
|
let dummy_return_type = unifier.get_fresh_var().0;
|
||||||
|
type_var_to_concrete_def.insert(
|
||||||
|
dummy_return_type,
|
||||||
|
TypeAnnotation::PrimitiveKind(primitives.none),
|
||||||
|
);
|
||||||
|
dummy_return_type
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// if is the "__init__" function, the return type is self
|
// if is the "__init__" function, the return type is self
|
||||||
let dummy_return_type = unifier.get_fresh_var().0;
|
let dummy_return_type = unifier.get_fresh_var().0;
|
||||||
|
|
|
@ -56,6 +56,10 @@ impl SymbolResolver for Resolver {
|
||||||
|
|
||||||
def fun(self):
|
def fun(self):
|
||||||
self.b = self.b + 3.0
|
self.b = self.b + 3.0
|
||||||
|
"},
|
||||||
|
indoc! {"
|
||||||
|
def foo(a: float):
|
||||||
|
a + 1.0
|
||||||
"}
|
"}
|
||||||
]
|
]
|
||||||
)]
|
)]
|
||||||
|
|
Loading…
Reference in New Issue