Skip to content

Commit

Permalink
Fix assertion failure on unused reference to _ (#2091)
Browse files Browse the repository at this point in the history
Fix compiler assertion failure on unused reference to `_`
  • Loading branch information
Benoit Vey authored and jemc committed Jul 26, 2017
1 parent 6b066b0 commit 456b458
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/libponyc/codegen/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ LLVMValueRef LLVMLifetimeEnd(LLVMModuleRef module);

#define GEN_NOVALUE ((LLVMValueRef)1)

#define GEN_NOTNEEDED (LLVMConstInt(c->ibool, 0, false))
#define GEN_NOTNEEDED ((LLVMValueRef)2)

typedef struct genned_string_t genned_string_t;
DECLARE_HASHMAP(genned_strings, genned_strings_t, genned_string_t);
Expand Down
4 changes: 3 additions & 1 deletion src/libponyc/codegen/genexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ LLVMValueRef gen_expr(compile_t* c, ast_t* ast)
case TK_DONTCARE:
case TK_DONTCAREREF:
case TK_MATCH_DONTCARE:
ret = GEN_NOVALUE;
ret = GEN_NOTNEEDED;
break;

case TK_IF:
Expand Down Expand Up @@ -257,6 +257,8 @@ LLVMValueRef gen_assign_cast(compile_t* c, LLVMTypeRef l_type,
if(r_value <= GEN_NOVALUE)
return r_value;

pony_assert(r_value != GEN_NOTNEEDED);

LLVMTypeRef r_type = LLVMTypeOf(r_value);

if(r_type == l_type)
Expand Down
15 changes: 15 additions & 0 deletions test/libponyc/badpony.cc
Original file line number Diff line number Diff line change
Expand Up @@ -803,3 +803,18 @@ TEST_F(BadPonyTest, AsNestedUninferredNumericLiteral)

TEST_ERRORS_1(src, "Cannot cast uninferred literal");
}

TEST_F(BadPonyTest, DontCareUnusedBranchValue)
{
// From issue #2073
const char* src =
"actor Main\n"
" new create(env: Env) =>\n"
" if false then\n"
" None\n"
" else\n"
" _\n"
" end";

TEST_COMPILE(src);
}

0 comments on commit 456b458

Please sign in to comment.