Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit d371746

Browse files
committed
Merge pull request #73 from non/topic/typelambda-cleanup-v0
Topic/typelambda cleanup v0
2 parents 050e36f + b89ef77 commit d371746

File tree

7 files changed

+72
-6
lines changed

7 files changed

+72
-6
lines changed

src/compiler/scala/tools/nsc/ast/parser/Parsers.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ self =>
928928

929929
/** {{{
930930
* SimpleType ::= SimpleType TypeArgs
931-
* | `[' Types `]' `=>' Type
931+
* | `[' VariantTypeParam {`,' VariantTypeParam} `]'] `=>' Type
932932
* | SimpleType `#' Id
933933
* | StableId
934934
* | Path `.' type
@@ -944,7 +944,10 @@ self =>
944944
case LBRACKET =>
945945
atPos(start) {
946946
val ts = typeParamClauseOpt(freshTypeName("typelambda"), null)
947-
if (in.token == ARROW) {
947+
if (ts.isEmpty) {
948+
syntaxError("missing type parameters", skipIt = false)
949+
errorTypeTree
950+
} else if (in.token == ARROW) {
948951
in.skipToken()
949952
makeTypeLambdaTypeTree(ts, typ())
950953
} else {

src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,13 @@ abstract class TreeBuilder {
155155

156156
/** Create a type lambda tree */
157157
def makeTypeLambdaTypeTree(argtpes: List[TypeDef], restpe: Tree): Tree = {
158-
val name = freshTypeName("L")
158+
val name = freshTypeName("L$")
159159
SelectFromTypeTree(
160160
CompoundTypeTree(
161161
Template(
162-
Select(Select(Ident("_root_"), "scala"), newTypeName("AnyRef")) :: Nil,
163-
ValDef(Modifiers(0), "_", TypeTree(), EmptyTree),
164-
TypeDef(Modifiers(0), name, argtpes, restpe) :: Nil)), name)
162+
gen.rootScalaDot(tpnme.AnyRef) :: Nil,
163+
ValDef(NoMods, nme.WILDCARD, TypeTree(), EmptyTree),
164+
TypeDef(NoMods, name, argtpes, restpe) :: Nil)), name)
165165
}
166166

167167
/** Append implicit parameter section if `contextBounds` nonempty */

test/files/neg/typelambda1.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
typelambda1.scala:5: error: type L$1 takes type parameters
2+
qux[[x] => [y] => (x, y)]
3+
^
4+
one error found

test/files/neg/typelambda1.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object Test {
2+
3+
def qux[Q[_]] = 999
4+
5+
qux[[x] => [y] => (x, y)]
6+
}

test/files/neg/typelambda2.check

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
typelambda2.scala:5: error: kinds of the type arguments ([x[_]] => x[Double]) do not conform to the expected kinds of the type parameters (type Q).
2+
[x[_]] => x[Double]'s type parameters do not match type Q's expected parameters:
3+
type x has one type parameter, but type _ has none
4+
qux[[x[_]] => x[Double]]
5+
^
6+
typelambda2.scala:6: error: [x, y] => x => y takes two type parameters, expected: one
7+
qux[[x, y] => (x => y)]
8+
^
9+
typelambda2.scala:7: error: not found: type x
10+
qux[x => y]
11+
^
12+
typelambda2.scala:7: error: not found: type y
13+
qux[x => y]
14+
^
15+
typelambda2.scala:7: error: <error> => <error> takes no type parameters, expected: one
16+
qux[x => y]
17+
^
18+
5 errors found

test/files/neg/typelambda2.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object Test {
2+
3+
def qux[Q[_]] = 999
4+
5+
qux[[x[_]] => x[Double]]
6+
qux[[x, y] => (x => y)]
7+
qux[x => y]
8+
}

test/files/pos/typelambda.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
trait Monad[M[_]] {
2+
def point[A](a: A): M[A]
3+
def bind[A, B](ma: M[A])(f: A => M[B]): M[B]
4+
}
5+
6+
object Test {
7+
trait RightMonad[L] extends Monad[[x] => Either[L, x]] {
8+
def point[A](a: A): Either[L, A] =
9+
Right(a)
10+
def bind[A, B](ma: Either[L, A])(f: A => Either[L, B]): Either[L, B] =
11+
ma.right.flatMap(f)
12+
}
13+
14+
def test1[A[_]] = 999
15+
16+
test1[[a] => (a, a)]
17+
test1[[b] => Unit]
18+
test1[[x] => x => x]
19+
test1[[y] => Option[y]]
20+
test1[[z] => Map[z, Set[z]]]
21+
22+
def test2[X[_[_]]] = 999
23+
24+
test2[[abc[_]] => abc[Int]]
25+
test2[[xyz[_]] => xyz[xyz[xyz[Unit]]]]
26+
test2[[q[_]] => Monad[q]]
27+
}

0 commit comments

Comments
 (0)