Skip to content

Commit

Permalink
Fixes #153
Browse files Browse the repository at this point in the history
  • Loading branch information
eldritchconundrum committed Apr 17, 2024
1 parent bb7a4a1 commit 845fe68
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rewriter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ module private RewriterImpl =
let simplifyStmt = function
| Block [] as e -> e
| Block b -> match simplifyBlock b with
| [stmt] -> stmt
| [stmt] as b when hasNoDecl b -> stmt
| stmts -> Block stmts
| Decl (ty, li) -> Decl (rwType ty, declsNotToInline li)
| ForD ((ty, d), cond, inc, body) -> ForD((rwType ty, declsNotToInline d), cond, inc, squeezeBlockWithComma body)
Expand Down
47 changes: 47 additions & 0 deletions tests/unit/shadowing.frag
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,51 @@ float g(float f)
f+=g;
}
return f;
}

int m1()
{
int x = 1;
if (rand() >.5)
{
int x = 2, y = x; // y is initialized to 2
return y;
}
}

struct S{ int x; };

S m2()
{
S S = S(0); // 'S' is only visible as a struct and constructor
return S; // 'S' is now visible as a variable
}

void m4(int k)
{
//int k = k + 3; // redeclaration error of the name k
{
int k = k + 3; // 2nd k is parameter, initializing nested first k
int m = k; // use of new k, which is hiding the parameter
}
return k;

//int x = x; // Error if x has not been previously defined.
// If the previous definition of x was in this
// same scope, this causes a redeclaration error.
}

void m5(float k)
{
float m = 9.;
m = 14.;
{
float k = k + 3.; // 2nd k is parameter, initializing nested first k
m = k; // use of new k, which is hiding the parameter
}
return k + 2. * m;
}
void m6()
{
m5(55.);
}
25 changes: 25 additions & 0 deletions tests/unit/shadowing.frag.expected
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,28 @@ float g(float f)
}
return f;
}
int m1()
{
if(rand()>.5)
return 2;
}
struct S{int x;};
S m2()
{
return S(0);
}
void m4(int k)
{
return k;
}
void m5()
{
float m=9.;
m=14.;
m=58.;
return 55.+2.*m;
}
void m6()
{
m5();
}

0 comments on commit 845fe68

Please sign in to comment.