diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-02-09 17:44:32 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-02-09 17:44:32 -0800 |
commit | 6724890e36c5c3c6a6b79f1b5322b9c2932de9e1 (patch) | |
tree | 6076f4eaf1463ff94e07b8bcf161367f80ac528a | |
parent | cc9402b0d639dd5d9ac0b468b49a3ef7c2d80d39 (diff) | |
parent | 10ca1783d45dc9c87ea0c09f4ea046ac539f1749 (diff) | |
download | scala-6724890e36c5c3c6a6b79f1b5322b9c2932de9e1.tar.gz scala-6724890e36c5c3c6a6b79f1b5322b9c2932de9e1.tar.bz2 scala-6724890e36c5c3c6a6b79f1b5322b9c2932de9e1.zip |
Merge pull request #3476 from retronym/ticket/8207
SI-8207 Allow import qualified by self reference
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Namers.scala | 10 | ||||
-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 |
4 files changed, 24 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 632e25aa2e..886dbed6d6 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -1408,8 +1408,14 @@ trait Namers extends MethodSynthesis { if (expr1.isErrorTyped) ErrorType else { - if (!treeInfo.isStableIdentifierPattern(expr1)) - typer.TyperErrorGen.UnstableTreeError(expr1) + expr1 match { + case This(_) => + // SI-8207 okay, typedIdent expands Ident(self) to C.this which doesn't satisfy the next case + // TODO should we change `typedIdent` not to expand to the `Ident` to a `This`? + case _ if treeInfo.isStableIdentifierPattern(expr1) => + case _ => + typer.TyperErrorGen.UnstableTreeError(expr1) + } val newImport = treeCopy.Import(imp, expr1, selectors).asInstanceOf[Import] checkSelectors(newImport) 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 +} |