diff --git a/src/libponyc/codegen/genmatch.c b/src/libponyc/codegen/genmatch.c index fc4023ce59..7fba3a45cd 100644 --- a/src/libponyc/codegen/genmatch.c +++ b/src/libponyc/codegen/genmatch.c @@ -804,7 +804,7 @@ LLVMValueRef gen_match(compile_t* c, ast_t* ast) ast_t* pattern_type = deferred_reify(reify, ast_type(the_case), c->opt); bool ok = true; - matchtype_t match = is_matchtype(match_type, pattern_type, NULL, c->opt); + matchtype_t match = is_matchtype_with_consumed_pattern(match_type, pattern_type, NULL, c->opt); ast_free_unattached(pattern_type); diff --git a/src/libponyc/codegen/gentrace.c b/src/libponyc/codegen/gentrace.c index f0f381178e..b625abf494 100644 --- a/src/libponyc/codegen/gentrace.c +++ b/src/libponyc/codegen/gentrace.c @@ -546,7 +546,7 @@ static int trace_cap_nominal(pass_opt_t* opt, ast_t* type, ast_t* orig, // val and tag in that order. if(orig_cap == TK_ISO) { - if(is_astype(orig, type, NULL, opt) == MATCHTYPE_ACCEPT) + if(is_matchtype(orig, type, NULL, opt) == MATCHTYPE_ACCEPT) { return PONY_TRACE_MUTABLE; } else { @@ -556,7 +556,7 @@ static int trace_cap_nominal(pass_opt_t* opt, ast_t* type, ast_t* orig, if(ast_id(cap) == TK_VAL) { - if(is_astype(orig, type, NULL, opt) == MATCHTYPE_ACCEPT) + if(is_matchtype(orig, type, NULL, opt) == MATCHTYPE_ACCEPT) { ast_setid(cap, orig_cap); return PONY_TRACE_IMMUTABLE; @@ -568,7 +568,7 @@ static int trace_cap_nominal(pass_opt_t* opt, ast_t* type, ast_t* orig, pony_assert(ast_id(cap) == TK_TAG); int ret = -1; - if(is_astype(orig, type, NULL, opt) == MATCHTYPE_ACCEPT) + if(is_matchtype(orig, type, NULL, opt) == MATCHTYPE_ACCEPT) ret = PONY_TRACE_OPAQUE; ast_setid(cap, orig_cap); diff --git a/src/libponyc/expr/match.c b/src/libponyc/expr/match.c index 3dcb12f985..13680afd4d 100644 --- a/src/libponyc/expr/match.c +++ b/src/libponyc/expr/match.c @@ -507,7 +507,7 @@ bool expr_case(pass_opt_t* opt, ast_t* ast) bool ok = true; errorframe_t info = NULL; - switch(is_matchtype(match_type, pattern_type, &info, opt)) + switch(is_matchtype_with_consumed_pattern(match_type, pattern_type, &info, opt)) { case MATCHTYPE_ACCEPT: break; diff --git a/src/libponyc/expr/operator.c b/src/libponyc/expr/operator.c index 02f73395b6..4c8eda1d5f 100644 --- a/src/libponyc/expr/operator.c +++ b/src/libponyc/expr/operator.c @@ -551,7 +551,7 @@ static bool add_as_type(pass_opt_t* opt, ast_t* ast, ast_t* expr, ast_t* expr_type = ast_type(expr); errorframe_t info = NULL; - matchtype_t is_match = is_astype(expr_type, type, &info, opt); + matchtype_t is_match = is_matchtype(expr_type, type, &info, opt); if(is_match == MATCHTYPE_DENY_CAP) { errorframe_t frame = NULL; diff --git a/src/libponyc/type/matchtype.c b/src/libponyc/type/matchtype.c index 90e6218a79..db96c4ca8d 100644 --- a/src/libponyc/type/matchtype.c +++ b/src/libponyc/type/matchtype.c @@ -929,6 +929,12 @@ static matchtype_t is_x_match_x(ast_t* operand, ast_t* pattern, matchtype_t is_matchtype(ast_t* operand, ast_t* pattern, errorframe_t* errorf, pass_opt_t* opt) +{ + return is_x_match_x(operand, pattern, errorf, true, opt); +} + +matchtype_t is_matchtype_with_consumed_pattern(ast_t* operand, ast_t* pattern, errorframe_t* errorf, + pass_opt_t* opt) { ast_t* consumed_pattern = consume_type(pattern, TK_NONE, false); if (consumed_pattern == NULL) @@ -942,9 +948,3 @@ matchtype_t is_matchtype(ast_t* operand, ast_t* pattern, errorframe_t* errorf, return rslt; } - -matchtype_t is_astype(ast_t* operand, ast_t* pattern, errorframe_t* errorf, - pass_opt_t* opt) -{ - return is_x_match_x(operand, pattern, errorf, true, opt); -} diff --git a/src/libponyc/type/matchtype.h b/src/libponyc/type/matchtype.h index 9f3ef536e6..9396a42d84 100644 --- a/src/libponyc/type/matchtype.h +++ b/src/libponyc/type/matchtype.h @@ -45,11 +45,9 @@ matchtype_t is_matchtype(ast_t* operand, ast_t* pattern, errorframe_t* errorf, pass_opt_t* opt); /** - * Same as is_matchtype() but specifically designed to work with `as` which - * under the steed model, needs to act differently than matchwith respect - * to iso. + * Same as is_matchtype() but it consumes the pattern type and then sees if a match works. Used in match.c and genmatch.c to close issue #4579. */ -matchtype_t is_astype(ast_t* operand, ast_t* pattern, errorframe_t* errorf, +matchtype_t is_matchtype_with_consumed_pattern(ast_t* operand, ast_t* pattern, errorframe_t* errorf, pass_opt_t* opt); PONY_EXTERN_C_END