Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid flattening arrow to type param, fixing typechecking when reified with another type param. #2692

Merged
merged 1 commit into from
May 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/libponyc/type/typeparam.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,17 @@ static void typeparam_current_inner(ast_t* type, ast_t* scope)
break;
}

// These can appear on the left side of a TK_ARROW,
// but we have no need to do anything with them here.
case TK_ISO:
case TK_TRN:
case TK_REF:
case TK_VAL:
case TK_BOX:
case TK_TAG:
case TK_THISTYPE:
break;

default:
pony_assert(0);
}
Expand Down
5 changes: 4 additions & 1 deletion src/libponyc/type/viewpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ ast_t* viewpoint_type(ast_t* l_type, ast_t* r_type)
return type;
}

case TK_NOMINAL:
case TK_TYPEPARAMREF:
upper = VIEW_UPPER_NO;
break;

case TK_NOMINAL:
{
ast_t* cap = cap_fetch(r_type);

Expand Down
26 changes: 26 additions & 0 deletions test/libponyc/type_check_subtype.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1133,3 +1133,29 @@ TEST_F(SubTypeTest, TupleValRefNotSubAnyShare)

TEST_ERRORS_1(src, "type argument is outside its constraint");
}


TEST_F(SubTypeTest, BoxArrowTypeParamReifiedWithTypeParam)
{
const char* src =
"interface _V[A: _V[A] ref]\n"
" fun ref reset(delta: A): A\n"
" fun ref converge(other: box->A)\n"

"class ref Container[V: _V[V] ref] is _V[Container[V]]\n"
" let _value: V\n"
" new ref create(value': V) => _value = value'\n"

" fun ref reset(delta: Container[V]): Container[V] =>\n"
" _value.reset(delta._value)\n"
" delta\n"

" fun ref converge(other: Container[V] box) =>\n"
" _value.converge(other._value)\n"

"actor Main\n"
" new create(env: Env) =>\n"
" None";

TEST_COMPILE(src);
}