Skip to content

Commit

Permalink
BL-978
Browse files Browse the repository at this point in the history
  • Loading branch information
bdw429s committed Jan 23, 2025
1 parent 085c864 commit 88091ae
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,18 @@ public Key findClosestFunctionName() {
@Override
public IScope getDefaultAssignmentScope() {
// CF Source sets into variable scope. BoxLang defaults to local scope
return getFunction().getSourceType().equals( BoxSourceType.CFSCRIPT )
|| getFunction().getSourceType().equals( BoxSourceType.CFTEMPLATE )
? getScopeNearby( VariablesScope.name )
: localScope;
var sourceType = getFunction().getSourceType();
if ( sourceType.equals( BoxSourceType.CFSCRIPT ) || sourceType.equals( BoxSourceType.CFTEMPLATE ) ) {
// If we are in a static initializer or a function not in a class at all, defer to the parent
if ( getParent() instanceof StaticClassBoxContext || !isInClass() ) {
return getParent().getDefaultAssignmentScope();
} else {
// Otherwise, non-static functions in a class use the closest variables scope
return getScopeNearby( VariablesScope.name );
}
} else {
return localScope;
}
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/TestCases/phase3/ClassTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1671,4 +1671,13 @@ public void testUserASMError() {
context );
}

@Test
public void testUserStaticError() {
instance.executeSource(
"""
new src.test.java.TestCases.phase3.StaticError()
""",
context );
}

}
12 changes: 12 additions & 0 deletions src/test/java/TestCases/phase3/StaticError.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
component {
static {
zzz = (
() => {
var pattern = 42; // uncomment for breakage
return 42;
}
)( );
}

println(static.zzz)
}

0 comments on commit 88091ae

Please sign in to comment.