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

Don’t consider type arguments inside a constraint as constraints. #1870

Merged
merged 1 commit into from
Apr 29, 2017
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
2 changes: 2 additions & 0 deletions src/libponyc/ast/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ bool frame_push(typecheck_t* t, ast_t* ast)
t->frame->method_type = NULL;
t->frame->ffi_type = NULL;
t->frame->local_type = NULL;
t->frame->constraint = NULL;
t->frame->iftype_constraint = NULL;
break;

case TK_CASE:
Expand Down
5 changes: 2 additions & 3 deletions src/libponyc/pass/syntax.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,8 @@ static ast_result_t syntax_arrow(pass_opt_t* opt, ast_t* ast)
pony_assert(ast != NULL);
AST_GET_CHILDREN(ast, left, right);

if(((opt->check.frame->constraint != NULL) ||
(opt->check.frame->iftype_constraint != NULL)) &&
(opt->check.frame->method == NULL))
if((opt->check.frame->constraint != NULL) ||
(opt->check.frame->iftype_constraint != NULL))
{
ast_error(opt->check.errors, ast,
"arrow types can't be used as type constraints");
Expand Down
23 changes: 22 additions & 1 deletion test/libponyc/badpony.cc
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ TEST_F(BadPonyTest, TypeParamArrowClass)
TEST_COMPILE(src);
}

TEST_F(BadPonyTest, ArrowTypeParamInConstraint)
TEST_F(BadPonyTest, ArrowTypeParamInTypeConstraint)
{
// From issue #1694
const char* src =
Expand All @@ -413,6 +413,17 @@ TEST_F(BadPonyTest, ArrowTypeParamInConstraint)
"arrow types can't be used as type constraints");
}

TEST_F(BadPonyTest, ArrowTypeParamInMethodConstraint)
{
// From issue #1809
const char* src =
"class Foo\n"
" fun foo[X: box->Y, Y](x: X) => None";

TEST_ERRORS_1(src,
"arrow types can't be used as type constraints");
}

TEST_F(BadPonyTest, AnnotatedIfClause)
{
// From issue #1751
Expand Down Expand Up @@ -478,3 +489,13 @@ TEST_F(BadPonyTest, ThisDotFieldRef)

TEST_COMPILE(src);
}

TEST_F(BadPonyTest, CapSetInConstraintTypeParam)
{
const char* src =
"class A[X]\n"
"class B[X: A[Any #read]]\n";

TEST_ERRORS_1(src,
"a capability set can only appear in a type constraint");
}