diff --git a/mrpython/typechecking/typechecker.py b/mrpython/typechecking/typechecker.py index 0e826eb..3b3a253 100644 --- a/mrpython/typechecking/typechecker.py +++ b/mrpython/typechecking/typechecker.py @@ -2221,6 +2221,7 @@ def type_compare_SetType(expected_type, ctx, expr, expr_type, raise_error=True): SetType.type_compare = type_compare_SetType def type_compare_IterableType(expected_type, ctx, expr, expr_type, raise_error=True): + if isinstance(expr_type, OptionType): return check_option_type(type_compare_IterableType, expected_type, ctx, expr, expr_type, raise_error) @@ -2300,12 +2301,13 @@ def type_compare_TypeVariable(expected_type, ctx, expr, expr_type, raise_error=T ctx.call_type_env[-1][expected_type.var_name] = expr_type return True else: # not a call variable - if expected_type == expr_type: - return True - else: - if raise_error: - ctx.add_type_error(TypeComparisonError(ctx.function_def, expected_type, expr, expr_type, tr("Type mismatch for parameter #{} in call, expecting {} found: {}").format(expected_type.var_name[1:], expected_type, expr_type))) - return False + # XXX: is it always safe to accept the comparison ? + # or an error should be returned + return True + + # if raise_error: + # ctx.add_type_error(TypeComparisonError(ctx.function_def, expected_type, expr, expr_type, tr("Type mismatch for parameter #{} in call, expecting {} found: {}").format(expected_type.var_name[1:], expected_type, expr_type))) + # return False TypeVariable.type_compare = type_compare_TypeVariable diff --git a/test/progs/53_iterable_OK.py b/test/progs/53_iterable_OK.py new file mode 100644 index 0000000..86707aa --- /dev/null +++ b/test/progs/53_iterable_OK.py @@ -0,0 +1,20 @@ + +def groupes(f : Callable[[T], K], lst : List[T]) -> Dict[K, List[T]]: + """ + """ + dico : Dict[K,List[T]] = dict() + + e : T + for e in lst: + k : K = f(e) + if k in dico: + dico[k].append(e) + else: + dico[k] = [e] + + return dico + +# Jeu de tests +# TODO : str devrait ĂȘtre compatible avec Iterable[str] +assert groupes(len, ["a", "as", "asd", "aa", "asdf", "qwer", "aa"]) \ + == {1 : ["a"], 2 : ["as", "aa", "aa"], 3 : ["asd"], 4 : ["asdf", "qwer"]}