Skip to content

Commit

Permalink
Don’t consider type arguments inside a constraint as constraints. (#1870
Browse files Browse the repository at this point in the history
)

This better reflects their use. It allows arrow types and tuples to
appear in these positions. It also denies capability sets from appearing
in these positions. These have an extremely limited use, and are unlikely
to be used by anyone.

As a side effect, the default capability in these positions now
corresponds to the type default, rather than #any.

Also properly deny arrow types from appearing in constraints,
fixing #1809.
  • Loading branch information
plietar authored and jemc committed Apr 29, 2017
1 parent b1d77f0 commit bc479f4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
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");
}

0 comments on commit bc479f4

Please sign in to comment.