[squeak-dev] Review Request: UnassignedVariable.1.cs

christoph.thiede at student.hpi.uni-potsdam.de christoph.thiede at student.hpi.uni-potsdam.de
Fri Nov 25 17:43:18 UTC 2022


=============== 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.html#:~:text=the%20language%20used%20in%20parser%3E%3E%23queryundefined

=============== 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"]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20221125/113ba453/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: UnassignedVariable.1.cs
Type: application/octet-stream
Size: 3150 bytes
Desc: not available
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20221125/113ba453/attachment.obj>


More information about the Squeak-dev mailing list