Compiler-Tests.st 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. Smalltalk current createPackage: 'Compiler-Tests'!
  2. TestCase subclass: #ASTParsingTest
  3. instanceVariableNames: ''
  4. package: 'Compiler-Tests'!
  5. !ASTParsingTest methodsFor: 'convenience'!
  6. analyze: aNode forClass: aClass
  7. (SemanticAnalyzer on: aClass) visit: aNode.
  8. ^ aNode
  9. ! !
  10. !ASTParsingTest methodsFor: 'parsing'!
  11. parse: aString
  12. ^ Smalltalk current parse: aString
  13. !
  14. parse: aString forClass: aClass
  15. ^ self analyze: (self parse: aString) forClass: aClass
  16. ! !
  17. ASTParsingTest subclass: #ASTPCNodeVisitorTest
  18. instanceVariableNames: ''
  19. package: 'Compiler-Tests'!
  20. !ASTPCNodeVisitorTest methodsFor: 'factory'!
  21. astPCNodeVisitor
  22. ^ ASTPCNodeVisitor new
  23. context: (AIContext new
  24. yourself);
  25. yourself
  26. !
  27. astPCNodeVisitorForSelector: aString
  28. ^ ASTPCNodeVisitor new
  29. selector: aString;
  30. context: (AIContext new
  31. yourself);
  32. yourself
  33. ! !
  34. !ASTPCNodeVisitorTest methodsFor: 'tests'!
  35. testJSStatementNode
  36. | ast visitor |
  37. ast := self parse: 'foo <consolee.log(1)>' forClass: Object.
  38. self assert: (self astPCNodeVisitor
  39. visit: ast;
  40. currentNode) isJSStatementNode
  41. !
  42. testMessageSend
  43. | ast |
  44. ast := self parse: 'foo self asString yourself. ^ self asBoolean' forClass: Object.
  45. self assert: ((self astPCNodeVisitorForSelector: 'yourself')
  46. visit: ast;
  47. currentNode) selector equals: 'yourself'
  48. !
  49. testMessageSendWithBlocks
  50. | ast |
  51. ast := self parse: 'foo true ifTrue: [ [ self asString yourself ] value. ]. ^ self asBoolean' forClass: Object.
  52. self assert: ((self astPCNodeVisitorForSelector: 'yourself')
  53. visit: ast;
  54. currentNode) selector equals: 'yourself'
  55. !
  56. testMessageSendWithInlining
  57. | ast |
  58. ast := self parse: 'foo true ifTrue: [ self asString yourself ]. ^ self asBoolean' forClass: Object.
  59. self assert: ((self astPCNodeVisitorForSelector: 'yourself')
  60. visit: ast;
  61. currentNode) selector equals: 'yourself'.
  62. ast := self parse: 'foo true ifTrue: [ self asString yourself ]. ^ self asBoolean' forClass: Object.
  63. self assert: ((self astPCNodeVisitorForSelector: 'asBoolean')
  64. visit: ast;
  65. currentNode) selector equals: 'asBoolean'
  66. !
  67. testNoMessageSend
  68. | ast |
  69. ast := self parse: 'foo ^ self' forClass: Object.
  70. self assert: (self astPCNodeVisitor
  71. visit: ast;
  72. currentNode) isNil
  73. !
  74. testPC
  75. | ast visitor |
  76. ast := self parse: 'foo <console.log(1)>' forClass: Object.
  77. self assert: (self astPCNodeVisitor
  78. visit: ast;
  79. currentNode) isJSStatementNode
  80. ! !
  81. ASTParsingTest subclass: #CodeGeneratorTest
  82. instanceVariableNames: 'receiver'
  83. package: 'Compiler-Tests'!
  84. !CodeGeneratorTest methodsFor: 'accessing'!
  85. codeGeneratorClass
  86. ^ CodeGenerator
  87. ! !
  88. !CodeGeneratorTest methodsFor: 'factory'!
  89. compiler
  90. ^ Compiler new
  91. codeGeneratorClass: self codeGeneratorClass;
  92. yourself
  93. ! !
  94. !CodeGeneratorTest methodsFor: 'initialization'!
  95. setUp
  96. receiver := DoIt new
  97. !
  98. tearDown
  99. "receiver := nil"
  100. ! !
  101. !CodeGeneratorTest methodsFor: 'testing'!
  102. should: aString receiver: anObject return: aResult
  103. | method result |
  104. receiver := anObject.
  105. method := self compiler install: aString forClass: anObject class category: 'tests'.
  106. result := receiver perform: method selector.
  107. anObject class removeCompiledMethod: method.
  108. self assert: aResult equals: result
  109. !
  110. should: aString return: anObject
  111. ^ self
  112. should: aString
  113. receiver: receiver
  114. return: anObject
  115. ! !
  116. !CodeGeneratorTest methodsFor: 'tests'!
  117. testAssignment
  118. self should: 'foo | a | a := true ifTrue: [ 1 ]. ^ a' return: 1.
  119. self should: 'foo | a | a := false ifTrue: [ 1 ]. ^ a' return: nil.
  120. self should: 'foo | a | ^ a := true ifTrue: [ 1 ]' return: 1
  121. !
  122. testBackslashSelectors
  123. self should: '\ arg ^ 4' return: 4.
  124. self should: '\\ arg ^ 42' return: 42
  125. !
  126. testBlockReturn
  127. self should: 'foo ^ #(1 2 3) collect: [ :each | true ifTrue: [ each + 1 ] ]' return: #(2 3 4).
  128. self should: 'foo ^ #(1 2 3) collect: [ :each | false ifFalse: [ each + 1 ] ]' return: #(2 3 4).
  129. self should: 'foo ^ #(1 2 3) collect: [ :each | each odd ifTrue: [ each + 1 ] ifFalse: [ each - 1 ] ]' return: #(2 1 4).
  130. !
  131. testCascades
  132. self should: 'foo ^ Array new add: 3; add: 4; yourself' return: #(3 4)
  133. !
  134. testDynamicArrayElementsOrdered
  135. self should: 'foo
  136. | x |
  137. x := 1.
  138. ^ { x. x := 2 }
  139. ' return: #(1 2).
  140. self should: 'foo
  141. | x |
  142. x := 1.
  143. ^ { x. true ifTrue: [ x := 2 ] }
  144. ' return: #(1 2).
  145. !
  146. testDynamicDictionaryElementsOrdered
  147. self should: 'foo
  148. | x |
  149. x := ''foo''->1.
  150. ^ #{ x. (true ifTrue: [ x := ''bar''->2 ]) }
  151. ' return: #{'foo'->1. 'bar'->2}.
  152. !
  153. testGlobalVar
  154. self should: 'foo ^ eval class' return: BlockClosure.
  155. self should: 'foo ^ Math cos: 0' return: 1.
  156. self should: 'foo ^ NonExistingVar' return: nil
  157. !
  158. testInnerTemporalDependentElementsOrdered
  159. self should: 'foo
  160. | x |
  161. x := Array.
  162. ^ x with: ''foo''->x with: ''bar''->(x := 2)
  163. ' return: {'foo'->Array. 'bar'->2}.
  164. self should: 'foo
  165. | x |
  166. x := Array.
  167. ^ x with: ''foo''->x with: ''bar''->(true ifTrue: [ x := 2 ])
  168. ' return: {'foo'->Array. 'bar'->2}.
  169. self should: 'foo
  170. | x |
  171. x := 1.
  172. ^ Array with: ''foo''->x with: ''bar''->(true ifTrue: [ x := 2 ])
  173. ' return: {'foo'->1. 'bar'->2}.
  174. self should: 'foo
  175. | x |
  176. x := 1.
  177. ^ { ''foo''->x. ''bar''->(true ifTrue: [ x := 2 ]) }
  178. ' return: {'foo'->1. 'bar'->2}.
  179. self should: 'foo
  180. | x |
  181. x := 1.
  182. ^ #{ ''foo''->x. ''bar''->(true ifTrue: [ x := 2 ]) }
  183. ' return: #{'foo'->1. 'bar'->2}.
  184. !
  185. testJSStatement
  186. self should: 'foo <return 2+3>' return: 5
  187. !
  188. testLiterals
  189. self should: 'foo ^ 1' return: 1.
  190. self should: 'foo ^ ''hello''' return: 'hello'.
  191. self should: 'foo ^ #(1 2 3 4)' return: #(1 2 3 4).
  192. self should: 'foo ^ {1. [:x | x ] value: 2. 3. [4] value}' return: #(1 2 3 4).
  193. self should: 'foo ^ true' return: true.
  194. self should: 'foo ^ false' return: false.
  195. self should: 'foo ^ #{1->2. 3->4}' return: #{1->2. 3->4}.
  196. self should: 'foo ^ #hello' return: #hello.
  197. self should: 'foo ^ -123.456' return: -123.456.
  198. self should: 'foo ^ -2.5e4' return: -25000.
  199. !
  200. testLocalReturn
  201. self should: 'foo ^ 1' return: 1.
  202. self should: 'foo ^ 1 + 1' return: 2.
  203. self should: 'foo ' return: receiver.
  204. self should: 'foo self asString' return: receiver.
  205. self should: 'foo | a b | a := 1. b := 2. ^ a + b' return: 3
  206. !
  207. testMessageSends
  208. self should: 'foo ^ 1 asString' return: '1'.
  209. self should: 'foo ^ 1 + 1' return: 2.
  210. self should: 'foo ^ 1 + 2 * 3' return: 9.
  211. self should: 'foo ^ 1 to: 3' return: #(1 2 3).
  212. self should: 'foo ^ 1 to: 5 by: 2' return: #(1 3 5)
  213. !
  214. testMultipleSequences
  215. self should: 'foo | a b c | a := 2. b := 3. c := a + b. ^ c * 6' return: 30
  216. !
  217. testMutableLiterals
  218. "Mutable literals must be aliased in cascades.
  219. See https://github.com/amber-smalltalk/amber/issues/428"
  220. self
  221. should: 'foo ^ #( 1 2 ) at: 1 put: 3; yourself'
  222. return: #(3 2)
  223. !
  224. testNestedIfTrue
  225. self should: 'foo ^ true ifTrue: [ false ifFalse: [ 1 ] ]' return: 1.
  226. self should: 'foo ^ true ifTrue: [ false ifTrue: [ 1 ] ]' return: nil.
  227. self should: 'foo true ifTrue: [ false ifFalse: [ ^ 1 ] ]' return: 1.
  228. self should: 'foo true ifTrue: [ false ifTrue: [ ^ 1 ] ]' return: receiver.
  229. !
  230. testNestedSends
  231. self should: 'foo ^ (Point x: (Point x: 2 y: 3) y: 4) asString' return: (Point x: (2@3) y: 4) asString
  232. !
  233. testNonLocalReturn
  234. self should: 'foo [ ^ 1 ] value' return: 1.
  235. self should: 'foo [ ^ 1 + 1 ] value' return: 2.
  236. self should: 'foo | a b | a := 1. b := 2. [ ^ a + b ] value. self halt' return: 3.
  237. self should: 'foo [ :x | ^ x + x ] value: 4. ^ 2' return: 8
  238. !
  239. testPascalCaseGlobal
  240. self should: 'foo ^Object' return: (smalltalk at: 'Object').
  241. self should: 'foo ^NonExistent' return: nil
  242. !
  243. testSendReceiverAndArgumentsOrdered
  244. self should: 'foo
  245. | x |
  246. x := 1.
  247. ^ Array with: x with: (true ifTrue: [ x := 2 ])
  248. ' return: #(1 2).
  249. self should: 'foo
  250. | x |
  251. x := Array.
  252. ^ x with: x with: (true ifTrue: [ x := 2 ])
  253. ' return: {Array. 2}.
  254. !
  255. testSuperSend
  256. self
  257. should: 'foo ^ super isBoolean'
  258. receiver: true
  259. return: false
  260. !
  261. testTempVariables
  262. self should: 'foo | a | ^ a' return: nil.
  263. self should: 'foo | AVariable | ^ AVariable' return: nil.
  264. self should: 'foo | a b c | ^ c' return: nil.
  265. self should: 'foo | a | [ | d | ^ d ] value' return: nil.
  266. self should: 'foo | a | a:= 1. ^ a' return: 1.
  267. self should: 'foo | AVariable | AVariable := 1. ^ AVariable' return: 1.
  268. !
  269. testThisContext
  270. self should: 'foo ^ [ thisContext ] value outerContext == thisContext' return: true
  271. !
  272. testifFalse
  273. self should: 'foo true ifFalse: [ ^ 1 ]' return: receiver.
  274. self should: 'foo false ifFalse: [ ^ 2 ]' return: 2.
  275. self should: 'foo ^ true ifFalse: [ 1 ]' return: nil.
  276. self should: 'foo ^ false ifFalse: [ 2 ]' return: 2.
  277. !
  278. testifFalseIfTrue
  279. self should: 'foo true ifFalse: [ ^ 1 ] ifTrue: [ ^ 2 ]' return: 2.
  280. self should: 'foo false ifFalse: [ ^ 2 ] ifTrue: [ ^1 ]' return: 2.
  281. self should: 'foo ^ true ifFalse: [ 1 ] ifTrue: [ 2 ]' return: 2.
  282. self should: 'foo ^ false ifFalse: [ 2 ] ifTrue: [ 1 ]' return: 2.
  283. !
  284. testifNil
  285. self should: 'foo ^ 1 ifNil: [ 2 ]' return: 1.
  286. self should: 'foo ^ nil ifNil: [ 2 ]' return: 2.
  287. self should: 'foo 1 ifNil: [ ^ 2 ]' return: receiver.
  288. self should: 'foo nil ifNil: [ ^ 2 ]' return: 2.
  289. !
  290. testifNilIfNotNil
  291. self should: 'foo ^ 1 ifNil: [ 2 ] ifNotNil: [ 3 ]' return: 3.
  292. self should: 'foo ^ nil ifNil: [ 2 ] ifNotNil: [ 3 ]' return: 2.
  293. self should: 'foo 1 ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]' return: 3.
  294. self should: 'foo nil ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]' return: 2.
  295. !
  296. testifNotNil
  297. self should: 'foo ^ 1 ifNotNil: [ 2 ]' return: 2.
  298. self should: 'foo ^ nil ifNotNil: [ 2 ]' return: nil.
  299. self should: 'foo 1 ifNotNil: [ ^ 2 ]' return: 2.
  300. self should: 'foo nil ifNotNil: [ ^ 2 ]' return: receiver.
  301. !
  302. testifNotNilWithArgument
  303. self should: 'foo ^ 1 ifNotNil: [ :val | val + 2 ]' return: 3.
  304. self should: 'foo ^ nil ifNotNil: [ :val | val + 2 ]' return: nil.
  305. self should: 'foo ^ 1 ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]' return: 3.
  306. self should: 'foo ^ nil ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]' return: 5.
  307. self should: 'foo ^ 1 ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]' return: 3.
  308. self should: 'foo ^ nil ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]' return: 5
  309. !
  310. testifTrue
  311. self should: 'foo false ifTrue: [ ^ 1 ]' return: receiver.
  312. self should: 'foo true ifTrue: [ ^ 2 ]' return: 2.
  313. self should: 'foo ^ false ifTrue: [ 1 ]' return: nil.
  314. self should: 'foo ^ true ifTrue: [ 2 ]' return: 2.
  315. !
  316. testifTrueIfFalse
  317. self should: 'foo false ifTrue: [ ^ 1 ] ifFalse: [ ^2 ]' return: 2.
  318. self should: 'foo true ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]' return: 1.
  319. self should: 'foo ^ false ifTrue: [ 2 ] ifFalse: [ 1 ]' return: 1.
  320. self should: 'foo ^ true ifTrue: [ 2 ] ifFalse: [ 1 ]' return: 2.
  321. ! !
  322. CodeGeneratorTest subclass: #InliningCodeGeneratorTest
  323. instanceVariableNames: ''
  324. package: 'Compiler-Tests'!
  325. !InliningCodeGeneratorTest methodsFor: 'accessing'!
  326. codeGeneratorClass
  327. ^ InliningCodeGenerator
  328. ! !
  329. CodeGeneratorTest subclass: #InterpreterTest
  330. instanceVariableNames: ''
  331. package: 'Compiler-Tests'!
  332. !InterpreterTest methodsFor: 'parsing'!
  333. analyze: aNode forClass: aClass
  334. (SemanticAnalyzer on: aClass) visit: aNode.
  335. ^ aNode
  336. !
  337. parse: aString
  338. ^ Smalltalk current parse: aString
  339. !
  340. parse: aString forClass: aClass
  341. ^ self analyze: (self parse: aString) forClass: aClass
  342. ! !
  343. !InterpreterTest methodsFor: 'private'!
  344. interpret: aString receiver: anObject withArguments: aDictionary
  345. "The food is a methodNode. Interpret the sequenceNode only"
  346. | ctx interpreter |
  347. interpreter := ASTInterpreter new.
  348. ctx := AIContext new
  349. receiver: anObject;
  350. interpreter: interpreter;
  351. yourself.
  352. aDictionary keysAndValuesDo: [ :key :value |
  353. ctx localAt: key put: value ].
  354. ^ interpreter
  355. context: ctx;
  356. interpret: (self parse: aString forClass: anObject class) nextChild;
  357. proceed;
  358. result
  359. ! !
  360. !InterpreterTest methodsFor: 'testing'!
  361. should: aString receiver: anObject return: aResult
  362. receiver := anObject.
  363. ^ self
  364. assert: (self interpret: aString receiver: receiver withArguments: #{})
  365. equals: aResult
  366. !
  367. should: aString return: anObject
  368. ^ self
  369. should: aString
  370. receiver: receiver
  371. return: anObject
  372. ! !
  373. TestCase subclass: #ScopeVarTest
  374. instanceVariableNames: ''
  375. package: 'Compiler-Tests'!
  376. !ScopeVarTest methodsFor: 'tests'!
  377. testClassRefVar
  378. | node |
  379. node := VariableNode new
  380. value: 'Object';
  381. yourself.
  382. SemanticAnalyzer new
  383. pushScope: MethodLexicalScope new;
  384. visit: node.
  385. self assert: node binding isClassRefVar
  386. !
  387. testInstanceVar
  388. | node scope |
  389. node := VariableNode new
  390. value: 'bzzz';
  391. yourself.
  392. scope := MethodLexicalScope new.
  393. scope addIVar: 'bzzz'.
  394. self assert: (scope bindingFor: node) isInstanceVar
  395. !
  396. testPseudoVar
  397. | node pseudoVars |
  398. pseudoVars := #('self' 'super' 'true' 'false' 'nil').
  399. pseudoVars do: [:each |
  400. node := VariableNode new
  401. value: each;
  402. yourself.
  403. self assert: (MethodLexicalScope new bindingFor: node) isPseudoVar ]
  404. !
  405. testTempVar
  406. | node scope |
  407. node := VariableNode new
  408. value: 'bzzz';
  409. yourself.
  410. scope := MethodLexicalScope new.
  411. scope addTemp: 'bzzz'.
  412. self assert: (scope bindingFor: node) isTempVar
  413. !
  414. testUnknownVar
  415. | node |
  416. node := VariableNode new
  417. value: 'bzzz';
  418. yourself.
  419. self assert: (MethodLexicalScope new bindingFor: node) isNil
  420. ! !
  421. TestCase subclass: #SemanticAnalyzerTest
  422. instanceVariableNames: 'analyzer'
  423. package: 'Compiler-Tests'!
  424. !SemanticAnalyzerTest methodsFor: 'running'!
  425. setUp
  426. analyzer := SemanticAnalyzer on: Object
  427. ! !
  428. !SemanticAnalyzerTest methodsFor: 'tests'!
  429. testAssignment
  430. | src ast |
  431. src := 'foo self := 1'.
  432. ast := smalltalk parse: src.
  433. self should: [analyzer visit: ast] raise: InvalidAssignmentError
  434. !
  435. testNonLocalReturn
  436. | src ast |
  437. src := 'foo | a | a + 1. ^ a'.
  438. ast := smalltalk parse: src.
  439. analyzer visit: ast.
  440. self deny: ast scope hasNonLocalReturn
  441. !
  442. testNonLocalReturn2
  443. | src ast |
  444. src := 'foo | a | a + 1. [ [ ^ a] ]'.
  445. ast := smalltalk parse: src.
  446. analyzer visit: ast.
  447. self assert: ast scope hasNonLocalReturn
  448. !
  449. testScope
  450. | src ast |
  451. src := 'foo | a | a + 1. [ | b | b := a ]'.
  452. ast := smalltalk parse: src.
  453. analyzer visit: ast.
  454. self deny: ast nodes first nodes last scope == ast scope.
  455. !
  456. testScope2
  457. | src ast |
  458. src := 'foo | a | a + 1. [ [ | b | b := a ] ]'.
  459. ast := smalltalk parse: src.
  460. analyzer visit: ast.
  461. self deny: ast nodes first nodes last nodes first nodes first scope == ast scope.
  462. !
  463. testScopeLevel
  464. | src ast |
  465. src := 'foo | a | a + 1. [ [ | b | b := a ] ]'.
  466. ast := smalltalk parse: src.
  467. analyzer visit: ast.
  468. self assert: ast scope scopeLevel equals: 1.
  469. self assert: ast nodes first nodes last nodes first nodes first scope scopeLevel equals: 3
  470. !
  471. testUnknownVariables
  472. | src ast |
  473. src := 'foo | a | b + a'.
  474. ast := smalltalk parse: src.
  475. self should: [ analyzer visit: ast ] raise: UnknownVariableError
  476. !
  477. testUnknownVariablesWithScope
  478. | src ast |
  479. src := 'foo | a b | [ c + 1. [ a + 1. d + 1 ]]'.
  480. ast := smalltalk parse: src.
  481. self should: [ analyzer visit: ast ] raise: UnknownVariableError
  482. !
  483. testVariableShadowing
  484. | src ast |
  485. src := 'foo | a | a + 1'.
  486. ast := smalltalk parse: src.
  487. analyzer visit: ast
  488. !
  489. testVariableShadowing2
  490. | src ast |
  491. src := 'foo | a | a + 1. [ | a | a := 2 ]'.
  492. ast := smalltalk parse: src.
  493. self should: [analyzer visit: ast] raise: ShadowingVariableError
  494. !
  495. testVariableShadowing3
  496. | src ast |
  497. src := 'foo | a | a + 1. [ | b | b := 2 ]'.
  498. ast := smalltalk parse: src.
  499. analyzer visit: ast
  500. !
  501. testVariableShadowing4
  502. | src ast |
  503. src := 'foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]'.
  504. ast := smalltalk parse: src.
  505. analyzer visit: ast
  506. !
  507. testVariableShadowing5
  508. | src ast |
  509. src := 'foo | a | a + 1. [ [ [ | a | a := 2 ] ] ]'.
  510. ast := smalltalk parse: src.
  511. self should: [analyzer visit: ast] raise: ShadowingVariableError
  512. !
  513. testVariablesLookup
  514. | src ast |
  515. src := 'foo | a | a + 1. [ | b | b := a ]'.
  516. ast := smalltalk parse: src.
  517. analyzer visit: ast.
  518. "Binding for `a` in the message send"
  519. self assert: ast nodes first nodes first receiver binding isTempVar.
  520. self assert: ast nodes first nodes first receiver binding scope == ast scope.
  521. "Binding for `b`"
  522. self assert: ast nodes first nodes last nodes first nodes first left binding isTempVar.
  523. self assert: ast nodes first nodes last nodes first nodes first left binding scope == ast nodes first nodes last scope.
  524. ! !