diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-02-02 15:11:43 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-02-03 14:31:34 +1000 |
commit | cc2e613189ce78d160ab88281736df948361c6ad (patch) | |
tree | b8db2e4cce5ed863048cc4f2372446565db41c06 /test | |
parent | 178e8df9b6a91375a6162721a0cbc2d90bcc7451 (diff) | |
download | scala-cc2e613189ce78d160ab88281736df948361c6ad.tar.gz scala-cc2e613189ce78d160ab88281736df948361c6ad.tar.bz2 scala-cc2e613189ce78d160ab88281736df948361c6ad.zip |
SI-9131 Fix use of apply syntactic sugar with by-name param
After typechecking a tree, the typer adapts it to the current
mode and expected type. If we are in FUNmode (typechecking the
qualifier of a value- or type-application), and the tree does not
already have a MethodType or PolyType, it is reinterepreted as
`qual.apply`.
In doing so, `insertApply` stabilizes the type of `qual`, e.g.
replacing `Ident(foo).setType(typeOf[Int])` with
`Ident(foo).setType(typeOf[foo.type])`.
However, this does not check for by-name parameters, which cannot
form the basis for a singleton type, as we can see by trying that
directly:
```
scala> def foo(a: => String) { type T = a.type }
<console>:7: error: stable identifier required, but a.type found.
def foo(a: => String) { type T = a.type }
^
```
When I last touched this code in SI-6206 / 267650cf9, I noted:
// TODO reconcile the overlap between Typers#stablize and TreeGen.stabilize
I didn't get around to that, but Adriaan gave that code a thorough
cleanup in fada1ef6b.
It appears that on the back of his work, we can now remove the local
stabilization logic in `insertApply` in favour of `TreeGen.stabilize`.
We then avoid the ill-formed singleton type, and the spurious
"apply is not a member" type error.
I did have to modify `isStableIdent` to check the symbol's info
in addition to the tree's type for by-name-ness.
Diffstat (limited to 'test')
-rw-r--r-- | test/files/pos/t9131.scala | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/files/pos/t9131.scala b/test/files/pos/t9131.scala new file mode 100644 index 0000000000..1a186a0a24 --- /dev/null +++ b/test/files/pos/t9131.scala @@ -0,0 +1,12 @@ +class Test { + + def byNameFunc(f: (=> (() => Any)) => Any): Unit = () + + def test = { + // "value apply is not a member of => () => Any" + byNameFunc(z => z()) + // okay + byNameFunc(z => z.apply()) + byNameFunc(z => {val f = z; f()}) + } +} |