Skip to content

Commit

Permalink
Null pointer for implicit cast. Fixes #399 (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin8105 authored and elliotchance committed Dec 5, 2017
1 parent af25cba commit 6247097
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tests/cast.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void test_castbool()

int main()
{
plan(7);
plan(11);

START_TEST(cast)
START_TEST(castbool)
Expand All @@ -41,5 +41,14 @@ int main()
char *c = (char *) 0;
is_true(c == NULL);

double *d2 = 0;
is_true(d2 == NULL);
int *i2 = 0;
is_true(i2 == NULL);
float *f2 = 0;
is_true(f2 == NULL);
char *c2 = 0;
is_true(c2 == NULL);

done_testing();
}
5 changes: 5 additions & 0 deletions transpiler/transpiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ func transpileToExpr(node ast.Node, p *program.Program, exprIsStmt bool) (
expr, exprType, preStmts, postStmts, err = transpileMemberExpr(n, p)

case *ast.ImplicitCastExpr:
if n.Kind == "NullToPointer" {
expr = util.NewIdent("nil")
exprType = types.NullPointer
return
}
if strings.Contains(n.Type, "enum") {
if d, ok := n.Children()[0].(*ast.DeclRefExpr); ok {
expr, exprType, err = util.NewIdent(d.Name), n.Type, nil
Expand Down

0 comments on commit 6247097

Please sign in to comment.