summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2003-11-07 12:11:21 +0000
committerMartin Odersky <odersky@gmail.com>2003-11-07 12:11:21 +0000
commit4bab79034d0056fb9982cbf31491880f961f8b53 (patch)
tree8cfdc73de23393c12c83098e57fcef34839afeb1
parentfc7e1bce49d8fd89b25b70277237ed41fb24965d (diff)
downloadscala-4bab79034d0056fb9982cbf31491880f961f8b53.tar.gz
scala-4bab79034d0056fb9982cbf31491880f961f8b53.tar.bz2
scala-4bab79034d0056fb9982cbf31491880f961f8b53.zip
*** empty log message ***
-rw-r--r--doc/reference/ScalaByExample.tex4
-rw-r--r--doc/reference/ScalaReference.tex21
-rw-r--r--sources/scala/Array.java2
-rw-r--r--sources/scala/Iterator.scala6
-rw-r--r--sources/scalac/ast/parser/Scanner.java36
-rw-r--r--sources/scalac/ast/parser/Scanner.scala7
-rw-r--r--sources/scalac/typechecker/Analyzer.java26
-rw-r--r--test/files/neg/bug191.check2
-rw-r--r--test/neg/bug191.check2
9 files changed, 65 insertions, 41 deletions
diff --git a/doc/reference/ScalaByExample.tex b/doc/reference/ScalaByExample.tex
index bea8c37665..7849be4882 100644
--- a/doc/reference/ScalaByExample.tex
+++ b/doc/reference/ScalaByExample.tex
@@ -1397,9 +1397,9 @@ As an example of how rational numbers can be used, here's a program
that prints the sum of all numbers $1/i$ where $i$ ranges from 1 to 10.
\begin{lstlisting}
var i = 1;
-var x = Rational(0, 1);
+var x = new Rational(0, 1);
while (i <= 10) {
- x = x + Rational(1,i);
+ x = x + new Rational(1,i);
i = i + 1;
}
System.out.println(x.numer + "/" + x.denom);
diff --git a/doc/reference/ScalaReference.tex b/doc/reference/ScalaReference.tex
index b5605be662..7b3602d07b 100644
--- a/doc/reference/ScalaReference.tex
+++ b/doc/reference/ScalaReference.tex
@@ -834,14 +834,6 @@ The erasure mapping is defined as follows.
\section{Implicit Conversions}
\label{sec:impl-conv}
-If $S \conforms T$, then values of type $S$ are implicitly {\em
-converted} to values type of $T$ in situations where a value of type
-$T$ is required. A conversion between two number types in \code{int},
-\code{long}, \code{float}, \code{double} creates a value of the target
-type representing the same number as the source. When used in an
-expression, a value of type \code{byte}, \code{char}, \code{short} is
-always implicitly converted to a value of type \code{int}.
-
The following implicit conversions are applied to expressions of
method type that are used as values, rather than being applied to some
arguments.
@@ -878,6 +870,16 @@ would violate the well-formedness rules for anonymous functions
parameters always need to be applied to arguments immediately.
\end{itemize}
+When used in an expression, a value of type \code{byte}, \code{char},
+\code{short} is always implicitly converted to a value of type
+\code{int}.
+
+If an expression $e$ has type $T$ where $T$ does not conform to the
+expected type $pt$ and $T$ has a member named \lstinline@coerce@, then
+the expression is typed and evaluated is if it was
+\listinline@$e$.coerce@.
+
+
\chapter{Basic Declarations and Definitions}
\label{sec:defs}
@@ -1175,6 +1177,9 @@ and upper bounds that constrain possible type arguments for the
parameter. $\pm$ is a {\em variance}, i.e.\ an optional prefix
of either \lstinline@+@, or \lstinline@-@.
+The upper bound $U$ in a type parameter clauses may denote be a final
+class. The lower bound may not denote a value type.
+
The names of all type parameters in a type parameter clause must be
pairwise different. The scope of a type parameter includes in each
case the whole type parameter clause. Therefore it is possible that a
diff --git a/sources/scala/Array.java b/sources/scala/Array.java
index 53ee7c242c..0ff31e9acb 100644
--- a/sources/scala/Array.java
+++ b/sources/scala/Array.java
@@ -11,7 +11,7 @@
package scala;
-/** @meta class [?T] extends scala.Function1[scala.Int, ?T];
+/** @meta class [+ ?T] extends scala.Function1[scala.Int, ?T];
*/
public abstract class Array
extends scala.Object
diff --git a/sources/scala/Iterator.scala b/sources/scala/Iterator.scala
index 1d5e505ee7..1f7a437b5f 100644
--- a/sources/scala/Iterator.scala
+++ b/sources/scala/Iterator.scala
@@ -34,12 +34,12 @@ object Iterator {
else error("next on empty iterator");
}
- def range(lo: Int, hi: Int) = new Iterator[Int] {
+ def range(lo: Int, end: Int) = new Iterator[Int] {
private var i = 0;
def hasNext: Boolean =
- i <= hi;
+ i < end;
def next: Int =
- if (i <= hi) { i = i + 1 ; i - 1 }
+ if (i < end) { i = i + 1 ; i - 1 }
else error("next on empty iterator");
}
diff --git a/sources/scalac/ast/parser/Scanner.java b/sources/scalac/ast/parser/Scanner.java
index 46b00d98d6..7d5910588b 100644
--- a/sources/scalac/ast/parser/Scanner.java
+++ b/sources/scalac/ast/parser/Scanner.java
@@ -226,6 +226,16 @@ public class Scanner extends TokenData {
nextch();
getOperatorRest(index);
return;
+ case '\\':
+ nextch();
+ if (ch == '"') {
+ getStringLit();
+ token = IDENTIFIER;
+ } else {
+ syntaxError(pos, "illegal character");
+ }
+ return;
+
case '/':
nextch();
if (!skipComment()) {
@@ -250,17 +260,7 @@ public class Scanner extends TokenData {
getNumber(index, 10);
return;
case '\"':
- nextch();
- litlen = 0;
- while (ch != '\"' && ch != CR && ch != LF && ch != SU)
- getlitch();
- if (ch == '\"') {
- token = STRINGLIT;
- name = Name.fromSource(lit, 0, litlen);
- nextch();
- }
- else
- syntaxError("unclosed character literal");
+ getStringLit();
return;
case '\'':
nextch();
@@ -497,6 +497,20 @@ public class Scanner extends TokenData {
}
}
+ private void getStringLit() {
+ nextch();
+ litlen = 0;
+ while (ch != '\"' && ch != CR && ch != LF && ch != SU)
+ getlitch();
+ if (ch == '\"') {
+ token = STRINGLIT;
+ name = Name.fromSource(lit, 0, litlen);
+ nextch();
+ }
+ else
+ syntaxError("unclosed character literal");
+ }
+
/** returns true if argument corresponds to a keyword.
* Used in dtd2scala tool.
*/
diff --git a/sources/scalac/ast/parser/Scanner.scala b/sources/scalac/ast/parser/Scanner.scala
index 5181812b9c..f36eec7f82 100644
--- a/sources/scalac/ast/parser/Scanner.scala
+++ b/sources/scalac/ast/parser/Scanner.scala
@@ -202,11 +202,12 @@ class Scanner(unit: Unit) extends TokenData {
nextch();
getOperatorRest(index);
return;
- case `\\' =>
+ case '\\' =>
nextch();
- if (ch == '"')//"
+ if (ch == '"') { //"
getStringLit();
- else
+ token = IDENTIFIER;
+ } else
syntaxError(pos, "illegal character");
return;
case '/' =>
diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java
index d4c0674a2e..64181df003 100644
--- a/sources/scalac/typechecker/Analyzer.java
+++ b/sources/scalac/typechecker/Analyzer.java
@@ -1400,15 +1400,19 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
break;
}
if ((mode & EXPRmode) != 0) {
- Symbol coerceMeth = tree.type.lookup(Names.coerce);
- if (coerceMeth != Symbol.NONE) {
- Type coerceType = checkAccessible(
- tree.pos, coerceMeth, tree.type.memberType(coerceMeth),
- tree);
- tree = make.Select(tree.pos, tree, Names.coerce)
- .setSymbol(coerceMeth)
- .setType(coerceType);
- return adapt(tree, mode, pt);
+ if (pt.symbol() == definitions.UNIT_CLASS) {
+ return gen.Block(new Tree[]{tree, gen.mkUnitLit(tree.pos)});
+ } else {
+ Symbol coerceMeth = tree.type.lookup(Names.coerce);
+ if (coerceMeth != Symbol.NONE) {
+ Type coerceType = checkAccessible(
+ tree.pos, coerceMeth, tree.type.memberType(coerceMeth),
+ tree);
+ tree = make.Select(tree.pos, tree, Names.coerce)
+ .setSymbol(coerceMeth)
+ .setType(coerceType);
+ return adapt(tree, mode, pt);
+ }
}
}
if ((mode & CONSTRmode) == 0) {
@@ -2068,7 +2072,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
pattype, definitions.BOOLEAN_TYPE());
Tree applyVisitor = transformVisitor(tree, pattype, restype);
if (!infer.isFullyDefined(restype))
- restype = applyVisitor.type;
+ restype = applyVisitor.type.deconst();
if (definitions.PARTIALFUNCTION_CLASS.isExternal())
// need to load tree for mixins
new SourceCompleter(global).complete(
@@ -2234,7 +2238,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
enterParams(vparams);
Tree.ValDef[] vparams1 = transform(vparams);
Tree body1 = transform(body, EXPRmode, restype);
- if (!infer.isFullyDefined(restype)) restype = body1.type;
+ if (!infer.isFullyDefined(restype)) restype = body1.type.deconst();
popContext();
return gen.mkFunction(
tree.pos, vparams1, body1, restype, context.owner);
diff --git a/test/files/neg/bug191.check b/test/files/neg/bug191.check
index 34666fdcd6..82681f970b 100644
--- a/test/files/neg/bug191.check
+++ b/test/files/neg/bug191.check
@@ -2,5 +2,5 @@ bug191.scala:11: type mismatch;
found : B.this.C
required: B.this.C
foo(new C);
- ^
+ ^
one error found
diff --git a/test/neg/bug191.check b/test/neg/bug191.check
index 34666fdcd6..82681f970b 100644
--- a/test/neg/bug191.check
+++ b/test/neg/bug191.check
@@ -2,5 +2,5 @@ bug191.scala:11: type mismatch;
found : B.this.C
required: B.this.C
foo(new C);
- ^
+ ^
one error found