[squeak-dev] The Trunk: Compiler-eem.480.mcz
marcel.taeumel at hpi.de
Wed Nov 23 10:24:51 UTC 2022
Hi Christoph --
> IMHO, it unnecessarily complicates the simple Smalltalk syntax. [...]
Nah, this is just a tooling change, not a syntactical one.
Yes, I would like to have this info skipped for #isNil as well. Note that one should not use #ifNotNilDo: anymore.
Am 23.11.2022 11:00:43 schrieb Thiede, Christoph <christoph.thiede at student.hpi.uni-potsdam.de>:
Hi Eliot, hi all,
I'm skeptical about this change, as it creates or expands a special role of the selectors #ifNil:, #ifNotNil:, and their combinations. IMHO, it unnecessarily complicates the simple Smalltalk syntax. While I know and sometimes dislike these UndefinedVariable notifications, too, I don't know whether differentiating them by the selector is the right strategy to improve this situation.
Consider the following examples:
| a b c d e f g h |
a ifNil: [a := 1].
c := b.
c ifNil: [c := 3].
#(1 2 3) sorted: d.
e := 5.
(e isNil or: [f isNil]) ifTrue: [e := f := 6].
g perform: #ifNotNil: with: [b := g].
h ifNotNilDo: [h := 8].
How would you explain to a naive Smalltalker which of these variables will be marked as undefined at this point and why? (Of course, you can explain it by pointing to the implementation, but I think that's a significantly less intuitive explanation than just saying "you must declare any variable before using it".)
Also, with this change, the compiler leaks the default value of any temporary variable, which we previously were able to hide at least partially.
In many cases, I think explicitly setting a temporary variable to nil before it is initialized within some non-trivial conditional complex would be more explicit, thus more readable, and something which we should generally encourage programmers to do.
Looking forward to your opinion!
Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von commits at source.squeak.org <commits at source.squeak.org>
Gesendet: Mittwoch, 23. November 2022 04:10:30
An: squeak-dev at lists.squeakfoundation.org; packages at lists.squeakfoundation.org
Betreff: [squeak-dev] The Trunk: Compiler-eem.480.mcz
Eliot Miranda uploaded a new version of Compiler to project The Trunk:
==================== Summary ====================
Time: 22 November 2022, 7:10:27.324796 pm
Do not warn of an uninitialized temporary if it is being sent ifNil: or ifNotNil:.
=============== Diff against Compiler-eem.479 ===============
Item was changed:
----- Method: Parser>>primaryExpression (in category 'expression types') -----
hereType == #word
[parseNode := self variable.
+ (parseNode isUndefTemp
+ and: [(#('ifNil:' 'ifNotNil:') includes: here) not
+ and: [self interactive]])
+ [self queryUndefined].
- (parseNode isUndefTemp and: [self interactive])
- ifTrue: [self queryUndefined].
hereType == #leftBracket
hereType == #leftBrace
hereType == #leftParenthesis
self expression ifFalse: [^self expected: 'expression'].
(self match: #rightParenthesis)
ifFalse: [^self expected: 'right parenthesis'].
(hereType == #string or: [hereType == #number or: [hereType == #literal or: [hereType == #character]]])
[parseNode := encoder encodeLiteral: self advance.
(here == #- and: [tokenType == #number and: [1 + hereEnd = mark]])
parseNode := encoder encodeLiteral: self advance negated.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Squeak-dev