Skip to content

Commit

Permalink
Compiler error instead of crash for too few args to constructor in ca…
Browse files Browse the repository at this point in the history
…se pattern.
  • Loading branch information
jemc authored and SeanTAllen committed May 3, 2017
1 parent 9964339 commit 027e695
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/libponyc/expr/match.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ static ast_t* make_pattern_type(pass_opt_t* opt, ast_t* pattern)

// Structural equality, pattern.eq(match).
ast_t* pattern_type = ast_type(pattern);

if(is_typecheck_error(pattern_type))
return NULL;

ast_t* fun = lookup(opt, pattern, pattern_type, stringtab("eq"));

if(fun == NULL)
Expand Down
15 changes: 15 additions & 0 deletions test/libponyc/badpony.cc
Original file line number Diff line number Diff line change
Expand Up @@ -499,3 +499,18 @@ TEST_F(BadPonyTest, CapSetInConstraintTypeParam)
TEST_ERRORS_1(src,
"a capability set can only appear in a type constraint");
}

TEST_F(BadPonyTest, MatchCasePatternConstructorTooFewArguments)
{
const char* src =
"class C\n"
" new create(key: String) => None\n"

"primitive Foo\n"
" fun apply(c: (C | None)) =>\n"
" match c\n"
" | C => None\n"
" end";

TEST_ERRORS_1(src, "not enough arguments");
}

0 comments on commit 027e695

Please sign in to comment.