diff options
-rw-r--r-- | doc/reference/ReferencePart.tex | 9 | ||||
-rw-r--r-- | sources/scala/Predef.scala | 61 | ||||
-rw-r--r-- | sources/scala/tools/scalac/typechecker/Infer.scala | 14 | ||||
-rwxr-xr-x | sources/scala/tools/scalac/typechecker/RefCheck.scala | 13 | ||||
-rw-r--r-- | sources/scala/xml/parsing/MarkupParser.scala | 2 | ||||
-rw-r--r-- | sources/scalac/symtab/Definitions.java | 2 | ||||
-rw-r--r-- | sources/scalac/symtab/Symbol.java | 2 |
7 files changed, 93 insertions, 10 deletions
diff --git a/doc/reference/ReferencePart.tex b/doc/reference/ReferencePart.tex index e8fae6419d..848a4ba846 100644 --- a/doc/reference/ReferencePart.tex +++ b/doc/reference/ReferencePart.tex @@ -1239,7 +1239,12 @@ new Pair[Int, Int](1, 2) . Type parameters appear in type definitions, class definitions, and -function definitions. The most general form of a type parameter is +function definitions. In this section we consider only type parameter +definitions with lower bounds ~\lstinline@>: $L$@~ and upper bounds +~\lstinline@<: $U$@~ whereas a discussion of view bounds +~\lstinline@<% $U$@~ are deferred to Section~\ref{sec:view-bounds}. + +The most general form of a type parameter is ~\lstinline@$\pm t$ >: $L$ <: $U$@. Here, $L$, and $U$ are lower and upper bounds that constrain possible type arguments for the parameter, and $\pm$ is a {\em variance}, i.e.\ an optional prefix @@ -3968,7 +3973,7 @@ implicitly augmented to val x: C = B.view(new B) \end{lstlisting} -\section{View-Bounds} +\section{View-Bounds}\label{sec:view-bounds} \syntax\begin{lstlisting} TypeParam ::= id [>: Type] [<% Type] diff --git a/sources/scala/Predef.scala b/sources/scala/Predef.scala index 87d92741e3..457d1a4ea9 100644 --- a/sources/scala/Predef.scala +++ b/sources/scala/Predef.scala @@ -54,12 +54,69 @@ object Predef { * @return the array containing elements xs. */ def Array[A](xs: A*): Array[A] = { - val array: Array[A] = new Array[A](xs.length); + val array = new Array[A](xs.length); var i = 0; for (val x <- xs.elements) { array(i) = x; i = i + 1; } array; } - +/* + def Array(x: boolean, xs: boolean*): Array[boolean] = { + val array = new Array[boolean](xs.length + 1); + array(0) = x; + var i = 1; + for (val x <- xs.elements) { array(i) = x; i = i + 1; } + array; + } + def Array(x: byte, xs: byte*): Array[byte] = { + val array = new Array[byte](xs.length + 1); + array(0) = x; + var i = 1; + for (val x <- xs.elements) { array(i) = x; i = i + 1; } + array; + } + def Array(x: short, xs: short*): Array[short] = { + val array = new Array[short](xs.length + 1); + array(0) = x; + var i = 1; + for (val x <- xs.elements) { array(i) = x; i = i + 1; } + array; + } + def Array(x: char, xs: char*): Array[char] = { + val array = new Array[char](xs.length + 1); + array(0) = x; + var i = 1; + for (val x <- xs.elements) { array(i) = x; i = i + 1; } + array; + } + def Array(x: int, xs: int*): Array[int] = { + val array = new Array[int](xs.length + 1); + array(0) = x; + var i = 1; + for (val x <- xs.elements) { array(i) = x; i = i + 1; } + array; + } + def Array(x: long, xs: long*): Array[long] = { + val array = new Array[long](xs.length + 1); + array(0) = x; + var i = 1; + for (val x <- xs.elements) { array(i) = x; i = i + 1; } + array; + } + def Array(x: float, xs: float*): Array[float] = { + val array = new Array[float](xs.length + 1); + array(0) = x; + var i = 1; + for (val x <- xs.elements) { array(i) = x; i = i + 1; } + array; + } + def Array(x: double, xs: double*): Array[double] = { + val array = new Array[double](xs.length + 1); + array(0) = x; + var i = 1; + for (val x <- xs.elements) { array(i) = x; i = i + 1; } + array; + } +*/ // errors and asserts ------------------------------------------------- def error(message: String): All = throw new Error(message); diff --git a/sources/scala/tools/scalac/typechecker/Infer.scala b/sources/scala/tools/scalac/typechecker/Infer.scala index c2f475c18b..3fec6d6c41 100644 --- a/sources/scala/tools/scalac/typechecker/Infer.scala +++ b/sources/scala/tools/scalac/typechecker/Infer.scala @@ -1224,7 +1224,19 @@ class Infer(global: scalac_Global, gen: TreeGen, make: TreeFactory) extends scal */ def specializes(ftpe1: Type, ftpe2: Type): boolean = ftpe1 match { case Type$MethodType(params, _) => - isApplicable(ftpe2, Symbol.getType(params), Type.AnyType) + //System.out.println("does " + ftpe1 + " specialize " + ftpe2);//DEBUG + val argtypes = Symbol.getType(params); + // if both formal and actual have REPEATED flag set on corresponding parameters, + // change actual to its element type. + // this is a hack which should be corrected once REPEATED is part of a type. + if (params.length > 0 && (params(params.length-1).flags & REPEATED) != 0) { + val params2 = ftpe2.firstParams(); + if (params2.length == params.length && (params2(params2.length-1).flags & REPEATED) != 0) { + argtypes(params.length-1) = argtypes(params.length-1) + .baseType(definitions.SEQ_CLASS).typeArgs()(0); + } + } + isApplicable(ftpe2, argtypes, Type.AnyType) case Type$PolyType(tparams, restype) => skipViewParams(tparams, restype) match { case Type$MethodType(params, _) => diff --git a/sources/scala/tools/scalac/typechecker/RefCheck.scala b/sources/scala/tools/scalac/typechecker/RefCheck.scala index 37e687e21b..93b514217e 100755 --- a/sources/scala/tools/scalac/typechecker/RefCheck.scala +++ b/sources/scala/tools/scalac/typechecker/RefCheck.scala @@ -974,8 +974,17 @@ class RefCheck(globl: scalac.Global) extends Transformer(globl) { // Tree node simplification--------------------------------------------------- private def elimTypeNode(tree: Tree): Tree = - if (tree.isType()) gen.mkType(tree.pos, tree.getType().deconst()) - else tree; + if (tree.isType()) { + val resultType = tree.getType().deconst(); + val resultArgs = resultType.typeArgs(); + if (resultType.symbol() == defs.ARRAY_CLASS && + resultArgs.length == 1 && + resultArgs(0).symbol() == defs.ANY_CLASS) + { + unit.warning(tree.pos, "Array[Any] not supported"); + } + gen.mkType(tree.pos, resultType); + } else tree; // Transformation ------------------------------------------------------------ diff --git a/sources/scala/xml/parsing/MarkupParser.scala b/sources/scala/xml/parsing/MarkupParser.scala index 65e7aadfdd..ffc7f6b303 100644 --- a/sources/scala/xml/parsing/MarkupParser.scala +++ b/sources/scala/xml/parsing/MarkupParser.scala @@ -243,7 +243,7 @@ abstract class MarkupParser[MarkupType] { } nextch; } - new String(Predef.Array[char](i.asInstanceOf[char])) + new String(Predef.Array(i.asInstanceOf[char])) } diff --git a/sources/scalac/symtab/Definitions.java b/sources/scalac/symtab/Definitions.java index 3a62282059..259e66a17d 100644 --- a/sources/scalac/symtab/Definitions.java +++ b/sources/scalac/symtab/Definitions.java @@ -506,7 +506,7 @@ public class Definitions { public Symbol PREDEF_ARRAY() { if (PREDEF_ARRAY == null) - PREDEF_ARRAY = loadTerm(PREDEF, Names.Array); + PREDEF_ARRAY = PREDEF.lookup(Names.Array).firstAlternative(); return PREDEF_ARRAY; } diff --git a/sources/scalac/symtab/Symbol.java b/sources/scalac/symtab/Symbol.java index f59d208629..5debfd11b7 100644 --- a/sources/scalac/symtab/Symbol.java +++ b/sources/scalac/symtab/Symbol.java @@ -1063,7 +1063,7 @@ public abstract class Symbol implements Modifiers, Kinds { } /** if type is a overloaded type, return first stable alternative - * else return array symbol itself + * else return symbol itself */ public Symbol stableAlternative() { switch (type()) { |