Default Scope Shadowing [message #1716439] |
Thu, 03 December 2015 15:26  |
Eclipse User |
|
|
|
I'm working through Lorenzo Bettini's book, and have gotten to the section on scoping. I'm reading the ebook, and at location 4124, he briefly discusses shadowing and proposes this test to verify that the default ScopeProvider will properly provide shadowing.
@Test def void testVariableShadowsParamLinking() {
'''
class A {
A m(A a) {
A a = null;
return a;
}
}
'''.parse.classes.head.methods.head => [
assertNoErrors
// the local variable should shadow the param
body.statements.head.assertSame(
(returnStatement.expression as SJSymbolRef).symbol)
]
}
However, this test fails for me with the default provider. Am I missing something, or is this just an incorrect statement from the book, or something that worked "out of the box" in prior versions of Xtext? The test passes with the custom ScopeProvider implementation presented later in the chapter.
Thanks!
|
|
|
|
Re: Default Scope Shadowing [message #1716483 is a reply to message #1716439] |
Fri, 04 December 2015 05:24   |
Eclipse User |
|
|
|
On 03/12/2015 21:26, Larry LeBron wrote:
> I'm working through Lorenzo Bettini's book, and have gotten to the
> section on scoping. I'm reading the ebook, and at location 4124, he
> briefly discusses shadowing and proposes this test to verify that the
> default ScopeProvider will properly provide shadowing.
>
>
> @Test def void testVariableShadowsParamLinking() {
> '''
> class A {
> A m(A a) {
> A a = null;
> return a;
> }
> }
> '''.parse.classes.head.methods.head => [
> assertNoErrors
> // the local variable should shadow the param
> body.statements.head.assertSame(
> (returnStatement.expression as SJSymbolRef).symbol)
> ]
> }
>
>
> However, this test fails for me with the default provider. Am I missing
> something, or is this just an incorrect statement from the book, or
> something that worked "out of the box" in prior versions of Xtext? The
> test passes with the custom ScopeProvider implementation presented later
> in the chapter.
Hi
how does this test fail with the default scope provider? I mean, does
assertNoErrors fail or the other assert?
cheers
Lorenzo
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book
|
|
|
|
Re: Default Scope Shadowing [message #1729455 is a reply to message #1716439] |
Thu, 14 April 2016 05:40  |
Eclipse User |
|
|
|
On 03/12/2015 21:26, Larry LeBron wrote:
> I'm working through Lorenzo Bettini's book, and have gotten to the
> section on scoping. I'm reading the ebook, and at location 4124, he
> briefly discusses shadowing and proposes this test to verify that the
> default ScopeProvider will properly provide shadowing.
>
>
> @Test def void testVariableShadowsParamLinking() {
> '''
> class A {
> A m(A a) {
> A a = null;
> return a;
> }
> }
> '''.parse.classes.head.methods.head => [
> assertNoErrors
> // the local variable should shadow the param
> body.statements.head.assertSame(
> (returnStatement.expression as SJSymbolRef).symbol)
> ]
> }
>
>
> However, this test fails for me with the default provider. Am I missing
> something, or is this just an incorrect statement from the book, or
> something that worked "out of the box" in prior versions of Xtext? The
> test passes with the custom ScopeProvider implementation presented later
> in the chapter.
>
> Thanks!
Hi
while working on this chapter for the 2nd edition I confirm that with
the default implementation of scope provider the test fails; probably
something has changed in Xtext after the book was written, sorry about
that. Of course, I fixed that in the new edition :)
cheers
Lorenzo
--
Prof. Lorenzo Bettini, Computer Science, DISIA, Univ. Firenze
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book
|
|
|
Powered by
FUDForum. Page generated in 0.24504 seconds