Skip to content

Commit

Permalink
Fix some conflict checking for inlined closures.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmacnak committed Jun 1, 2024
1 parent 56571d6 commit 84acb7d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions newspeak/NSCompilerTesting.ns
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,9 @@ public testParameterImmutabilityEnforced = (
public testParameterTemporaryConflictInBlock = (
assertCompilationErrorIn: 'class Sample = () (foo = ( [:x | | x | ] ))' including: 'x'.
)
public testParameterTemporaryConflictInInlinedBlock = (
assertCompilationErrorIn: 'class Sample = () (foo = ( 1 to: 10 do: [:x | | x | ] ))' including: 'x'.
)
public testParameterTemporaryConflictInMethod = (
assertCompilationErrorIn: 'class Sample = () (foo: x = ( | x | ))' including: 'x'.
)
Expand Down Expand Up @@ -1551,6 +1554,7 @@ public testReservedWordsAsMethods = (
assertNoCompilationErrorIn: 'class Sample = ()( thisContext = () )'.
)
public testReservedWordsAsParams = (
(* Method *)
assertCompilationErrorIn: 'class Sample = ()( foo: self = () )' including: 'self'.
assertCompilationErrorIn: 'class Sample = ()( foo: super = () )' including: 'super'.
assertCompilationErrorIn: 'class Sample = ()( foo: outer = () )' including: 'outer'.
Expand All @@ -1559,13 +1563,23 @@ public testReservedWordsAsParams = (
assertCompilationErrorIn: 'class Sample = ()( foo: nil = () )' including: 'nil'.
assertNoCompilationErrorIn: 'class Sample = ()( foo: thisContext = () )'.

(* Closure *)
assertCompilationErrorIn: 'class Sample = ()( foo = ( [:self | ] ) )' including: 'self'.
assertCompilationErrorIn: 'class Sample = ()( foo = ( [:super | ] ) )' including: 'super'.
assertCompilationErrorIn: 'class Sample = ()( foo = ( [:outer | ] ) )' including: 'outer'.
assertCompilationErrorIn: 'class Sample = ()( foo = ( [:true | ] ) )' including: 'true'.
assertCompilationErrorIn: 'class Sample = ()( foo = ( [:false | ] ) )' including: 'false'.
assertCompilationErrorIn: 'class Sample = ()( foo = ( [:nil | ] ) )' including: 'nil'.
assertNoCompilationErrorIn: 'class Sample = ()( foo = ( [:thisContext | ] ) )'.

(* Inlined closure *)
assertCompilationErrorIn: 'class Sample = ()( foo = ( 1 to: 2 do: [:self | ] ) )' including: 'self'.
assertCompilationErrorIn: 'class Sample = ()( foo = ( 1 to: 2 do: [:super | ] ) )' including: 'super'.
assertCompilationErrorIn: 'class Sample = ()( foo = ( 1 to: 2 do: [:outer | ] ) )' including: 'outer'.
assertCompilationErrorIn: 'class Sample = ()( foo = ( 1 to: 2 do: [:true | ] ) )' including: 'true'.
assertCompilationErrorIn: 'class Sample = ()( foo = ( 1 to: 2 do: [:false | ] ) )' including: 'false'.
assertCompilationErrorIn: 'class Sample = ()( foo = ( 1 to: 2 do: [:nil | ] ) )' including: 'nil'.
assertNoCompilationErrorIn: 'class Sample = ()( foo = ( 1 to: 2 do: [:thisContext | ] ) )'.
)
public testReservedWordsAsSlots = (
assertCompilationErrorIn: 'class Sample = ( | self | ) ()' including: 'self'.
Expand Down
5 changes: 5 additions & 0 deletions newspeak/NewspeakCompilation.ns
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public from: first <AST> to: last <AST> by: step <AST> do: block <BlockAST> = (
(* Create counter variable from block's parameter. *)
counterDecl:: block parameters removeLast. (* BOGUS: Should not mutate AST *)
checkForReservedWord: counterDecl name.
counterEntry:: LocalEntry forDeclaration: counterDecl atDepth: nil.
counterEntry induction: true.
loopScope at: counterDecl name put: counterEntry.
Expand Down Expand Up @@ -224,6 +225,10 @@ public from: first <AST> to: last <AST> by: step <AST> do: block <BlockAST> = (
copyPositionFrom: block.
(* inlined closure body *)
block body temporaries do:
[:temp |
temp name = counterDecl name ifTrue:
[Exception signal: 'Conflicting slots named ', temp name]].
body:: (rewriteInlinedBlockNode: block forValue: false) body.
(* add counter increment to loop body *)
Expand Down

0 comments on commit 84acb7d

Please sign in to comment.