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

Fix compiler assertion failure on unused reference to _ #2091

Merged
merged 1 commit into from
Jul 26, 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: 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to allow this? It seems like _ should only be used where you would otherwise be forced to give an identifier, not as an empty branch "filler" (None should be used for that).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently allow _ anywhere an identifier is allowed, except when the value would be needed. I don't really see a problem with allowing _ in the fixed case, and I'm also not sure where we'd draw the line between allowed and forbidden.

}