Skip to content

Commit

Permalink
Allow parameters and variables have same name as functions in local s…
Browse files Browse the repository at this point in the history
…cope
  • Loading branch information
kant2002 authored and ForNeVeR committed Sep 5, 2024
1 parent 453874f commit 54b303d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
6 changes: 0 additions & 6 deletions Cesium.CodeGen/Ir/Expressions/IdentifierExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ public IValue Resolve(IDeclarationScope scope)
if (var is not null && par is not null)
throw new CompilationException($"Variable {Identifier} is both available as a local and as a function parameter.");

if (var is not null && fun is not null)
throw new CompilationException($"Variable {Identifier} is both available as a local and as a function name.");

if (fun is not null && par is not null)
throw new CompilationException($"Variable {Identifier} is both available as a function name and as a function parameter.");

if (var is not null)
{
if (var.StorageClass == Declarations.StorageClass.Auto)
Expand Down
18 changes: 18 additions & 0 deletions Cesium.IntegrationTests/functions.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
void forward_declaration_void_1();
void forward_declaration_void_2(void);

void test(void)
{
}

int function_with_parameter(int test)
{
int y = test + 10;
return y;
}

int function_with_variable(int y)
{
int test = y + 10;
return test;
}

void declaration_void(void)
{
}
Expand All @@ -10,6 +26,8 @@ int foo()
declaration_void();
forward_declaration_void_1();
forward_declaration_void_2();
if (function_with_parameter(10) != 20) return -1;
if (function_with_variable(15) != 25) return -1;
return 42;
}

Expand Down

0 comments on commit 54b303d

Please sign in to comment.