=============== Summary ===============
Change Set: UnassignedVariable Date: 25 November 2022 Author: Christoph Thiede
Renames 'undeclared variable' warning to 'unassigned variable' as proposed by Eliot (emm) in [1]. Note that for now, I'd stick with the vocabulary #hasDef in ParseNodes as it a) aligns with #hasRef and b) has more than a few senders. Please report back whether you'd like to see that renamed, too.
[1] https://lists.squeakfoundation.org/pipermail/squeak-dev/2022-November/222668...
=============== Postscript ===============
CompilerExceptionsTest removeSelector: #testUndefinedVariable
=============== Diff ===============
CompilerExceptionsTest>>testUnassignedVariable {tests} · ct 11/25/2022 18:31 + testUnassignedVariable + + self + compiling: 'griffle | goo | ^ goo' + shouldRaise: UnassignedVariable + andSelect: [(text allRangesOfRegexMatches: '(?<=^ )goo') first] + testing: { + true -> [self assertSucceeded]. + false -> [self assertCanceled] }. + self + compiling: 'griffle [ | goo | ^ goo ] value' + shouldRaise: UnassignedVariable + andSelect: [(text allRangesOfRegexMatches: '(?<=^ )goo') first] + testing: { + true -> [self assertSucceeded]. + false -> [self assertCanceled] }.
Parser>>primaryExpression {expression types} · ct 11/25/2022 18:30 (changed) primaryExpression hereType == #word ifTrue: [parseNode := self variable. (parseNode isUndefTemp and: [(#(ifNil: ifNotNil: isNil notNil) includes: here) not and: [self interactive]]) ifTrue: - [self queryUndefined]. + [self queryUnassigned]. parseNode nowHasRef. ^ true]. hereType == #leftBracket ifTrue: [self advance. self blockExpression. ^true]. hereType == #leftBrace ifTrue: [self braceExpression. ^true]. hereType == #leftParenthesis ifTrue: [self advance. self expression ifFalse: [^self expected: 'expression']. (self match: #rightParenthesis) ifFalse: [^self expected: 'right parenthesis']. ^true]. (hereType == #string or: [hereType == #number or: [hereType == #literal or: [hereType == #character]]]) ifTrue: [parseNode := encoder encodeLiteral: self advance. ^true]. (here == #- and: [tokenType == #number and: [1 + hereEnd = mark]]) ifTrue: [self advance. parseNode := encoder encodeLiteral: self advance negated. ^true]. ^false
Parser>>queryUnassigned {error correction} · ct 11/25/2022 18:31 + queryUnassigned + | varStart varName | + varName := parseNode key. + varStart := self endOfLastToken + requestorOffset - varName size + 1. + self selectFrom: varStart to: varStart + varName size - 1 during: [ + (UnassignedVariable name: varName) ifFalse: [^ self fail]].
UnassignedVariable>>openMenuIn: {handling} · ct 11/25/2022 18:31 + openMenuIn: aBlock + + self resume: (Project uiManager + confirm: ('{1} appears to be unassigned at this point.\Proceed anyway?' translated withCRs asText + format: {name asText allBold}) + orCancel: [false] + title: 'Unassigned Variable' translated).
--- Sent from Squeak Inbox Talk ["UnassignedVariable.1.cs"]
On Fri, Nov 25, 2022 at 9:43 AM christoph.thiede@student.hpi.uni-potsdam.de wrote:
*=============== Summary ===============*
Change Set: UnassignedVariable Date: 25 November 2022 Author: Christoph Thiede
Renames 'undeclared variable' warning to 'unassigned variable' as proposed by Eliot (emm) in [1]. Note that for now, I'd stick with the vocabulary #hasDef in ParseNodes as it a) aligns with #hasRef and b) has more than a few senders. Please report back whether you'd like to see that renamed, too.
Since it's my proposal I shouldn't vote. But thankyou very much for the code!!
[1] https://lists.squeakfoundation.org/pipermail/squeak-dev/2022-November/222668...
*=============== Postscript ===============*
CompilerExceptionsTest removeSelector: #testUndefinedVariable
*=============== Diff ===============*
*CompilerExceptionsTest>>testUnassignedVariable {tests} · ct 11/25/2022 18:31*
- testUnassignedVariable
self
compiling: 'griffle | goo | ^ goo'
shouldRaise: UnassignedVariable
andSelect: [(text allRangesOfRegexMatches: '(?<=\^ )goo') first]
testing: {
true -> [self assertSucceeded].
false -> [self assertCanceled] }.
self
compiling: 'griffle [ | goo | ^ goo ] value'
shouldRaise: UnassignedVariable
andSelect: [(text allRangesOfRegexMatches: '(?<=\^ )goo') first]
testing: {
true -> [self assertSucceeded].
false -> [self assertCanceled] }.
*Parser>>primaryExpression {expression types} · ct 11/25/2022 18:30 (changed)* primaryExpression hereType == #word ifTrue: [parseNode := self variable. (parseNode isUndefTemp and: [(#(ifNil: ifNotNil: isNil notNil) includes: here) not and: [self interactive]]) ifTrue:
[self queryUndefined].
hereType == #leftBracket ifTrue: [self advance. self blockExpression. ^true]. hereType == #leftBrace ifTrue: [self braceExpression. ^true]. hereType == #leftParenthesis ifTrue: [self advance. self expression ifFalse: [^self expected: 'expression']. (self match: #rightParenthesis) ifFalse: [^self expected: 'right parenthesis']. ^true]. (hereType == #string or: [hereType == #number or: [hereType ==[self queryUnassigned]. parseNode nowHasRef. ^ true].
#literal or: [hereType == #character]]]) ifTrue: [parseNode := encoder encodeLiteral: self advance. ^true]. (here == #- and: [tokenType == #number and: [1 + hereEnd = mark]]) ifTrue: [self advance. parseNode := encoder encodeLiteral: self advance negated. ^true]. ^false
*Parser>>queryUnassigned {error correction} · ct 11/25/2022 18:31*
- queryUnassigned
| varStart varName |
varName := parseNode key.
varStart := self endOfLastToken + requestorOffset - varName size + 1.
self selectFrom: varStart to: varStart + varName size - 1 during: [
(UnassignedVariable name: varName) ifFalse: [^ self fail]].
*UnassignedVariable>>openMenuIn: {handling} · ct 11/25/2022 18:31*
- openMenuIn: aBlock
self resume: (Project uiManager
confirm: ('{1} appears to be unassigned at this point.\Proceed
anyway?' translated withCRs asText
format: {name asText allBold})
orCancel: [false]
title: 'Unassigned Variable' translated).
*Sent from **Squeak Inbox Talk https://github.com/hpi-swa-lab/squeak-inbox-talk* ["UnassignedVariable.1.cs"]
squeak-dev@lists.squeakfoundation.org