diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-02-06 13:00:09 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-02-06 13:28:57 +0100 |
commit | 10ca1783d45dc9c87ea0c09f4ea046ac539f1749 (patch) | |
tree | 5528090da9bd0161b83f7c85e067d39eb2928362 /test | |
parent | f59aeb58681d1dba8d32886de4785f6fb8dc9eff (diff) | |
download | scala-10ca1783d45dc9c87ea0c09f4ea046ac539f1749.tar.gz scala-10ca1783d45dc9c87ea0c09f4ea046ac539f1749.tar.bz2 scala-10ca1783d45dc9c87ea0c09f4ea046ac539f1749.zip |
SI-8207 Allow import qualified by self reference
This regressed in SI-6815 / #2374. We check if the result of
`typedQualifier(Ident(selfReference))` is a stable identifier
pattern. But we actually see the expansion to `C.this`, which
doesn't qualify.
This commit adds a special cases to `importSig` to compensate.
This is safe enough, because the syntax prevents the following:
scala> class C { import C.this.toString }
<console>:1: error: '.' expected but '}' found.
class C { import C.this.toString }
^
So loosening the check here doesn't admit invalid programs.
I've backed this up with a `neg` test.
The enclosed test also checks that we can use the self
reference in a singleton type, and as a qualifier in
a type selection (These weren't actually broken.)
Maybe it would be more principled to avoid expanding the self
reference in `typedIdent`. I can imagine that the current situation
is a pain for refactoring tools that try to implement a rename
refactoring, for example.
Seems a bit risky at the minute, but I've noted the idea
in a comment.
Diffstat (limited to 'test')
-rw-r--r-- | test/files/neg/t8207.check | 7 | ||||
-rw-r--r-- | test/files/neg/t8207.scala | 3 | ||||
-rw-r--r-- | test/files/pos/t8207.scala | 6 |
3 files changed, 16 insertions, 0 deletions
diff --git a/test/files/neg/t8207.check b/test/files/neg/t8207.check new file mode 100644 index 0000000000..59facd897a --- /dev/null +++ b/test/files/neg/t8207.check @@ -0,0 +1,7 @@ +t8207.scala:1: error: '.' expected but '}' found. +class C { import C.this.toString } + ^ +t8207.scala:3: error: '.' expected but '}' found. +class D { import D.this.toString } + ^ +two errors found diff --git a/test/files/neg/t8207.scala b/test/files/neg/t8207.scala new file mode 100644 index 0000000000..738ce381f4 --- /dev/null +++ b/test/files/neg/t8207.scala @@ -0,0 +1,3 @@ +class C { import C.this.toString } + +class D { import D.this.toString } diff --git a/test/files/pos/t8207.scala b/test/files/pos/t8207.scala new file mode 100644 index 0000000000..680b40f379 --- /dev/null +++ b/test/files/pos/t8207.scala @@ -0,0 +1,6 @@ +class C { me => + import me.{toString => ts} + locally(this: me.type) + trait T + type X = me.T +} |