From 2a2f314ebcb1990f334f78f2ca933d197286c6b2 Mon Sep 17 00:00:00 2001 From: Martijn Hoekstra Date: Fri, 26 Aug 2016 10:49:39 +0200 Subject: normalize paths for tests --- test/test/CompilerTest.scala | 3 +-- test/test/InterfaceEntryPointTest.scala | 2 +- test/test/OtherEntryPointsTest.scala | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/test/CompilerTest.scala b/test/test/CompilerTest.scala index 56b9e1099..b56b910bf 100644 --- a/test/test/CompilerTest.scala +++ b/test/test/CompilerTest.scala @@ -452,8 +452,7 @@ abstract class CompilerTest { processFileDir(sourceFile, { sf => if (extensionsToCopy.contains(sf.extension)) { dest.parent.jfile.mkdirs - dest.toFile.writeAll("/* !!!!! WARNING: DO NOT MODIFY. Original is at: $sf !!!!! */", - sf.slurp()) + dest.toFile.writeAll(s"/* !!!!! WARNING: DO NOT MODIFY. Original is at: $sf !!!!! */", sf.slurp) } else { log(s"WARNING: ignoring $sf") } diff --git a/test/test/InterfaceEntryPointTest.scala b/test/test/InterfaceEntryPointTest.scala index b193b5f64..438a9fa47 100644 --- a/test/test/InterfaceEntryPointTest.scala +++ b/test/test/InterfaceEntryPointTest.scala @@ -18,7 +18,7 @@ import scala.collection.mutable.ListBuffer */ class InterfaceEntryPointTest { @Test def runCompilerFromInterface = { - val sources = List("./tests/pos/HelloWorld.scala") + val sources = List("./tests/pos/HelloWorld.scala").map(p => new java.io.File(p).getPath()) val args = sources ++ List("-d", "./out/") val mainClass = Class.forName("dotty.tools.dotc.Main") diff --git a/test/test/OtherEntryPointsTest.scala b/test/test/OtherEntryPointsTest.scala index 0186b357b..5f8681d38 100644 --- a/test/test/OtherEntryPointsTest.scala +++ b/test/test/OtherEntryPointsTest.scala @@ -17,7 +17,7 @@ import scala.collection.mutable.ListBuffer */ class OtherEntryPointsTest { @Test def runCompiler = { - val sources = List("./tests/pos/HelloWorld.scala") + val sources = List("./tests/pos/HelloWorld.scala").map(p => new java.io.File(p).getPath()) val args = sources ++ List("-d", "./out/") val reporter = new CustomReporter @@ -31,7 +31,7 @@ class OtherEntryPointsTest { } @Test def runCompilerWithContext = { - val sources = List("./tests/pos/HelloWorld.scala") + val sources = List("./tests/pos/HelloWorld.scala").map(p => new java.io.File(p).getPath()) val args = sources ++ List("-d", "./out/") val reporter = new CustomReporter -- cgit v1.2.3 From e104be1fc10231bc3189573bc4229cc68501daf1 Mon Sep 17 00:00:00 2001 From: Martijn Hoekstra Date: Fri, 26 Aug 2016 11:09:07 +0200 Subject: ignore REPL transscript line ending differences --- test/test/TestREPL.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/test/TestREPL.scala b/test/test/TestREPL.scala index 1ba456ce2..9867cb4ec 100644 --- a/test/test/TestREPL.scala +++ b/test/test/TestREPL.scala @@ -34,7 +34,7 @@ class TestREPL(script: String) extends REPL { while (lines.hasNext && lines.head.startsWith(continuationPrompt)) { val continued = lines.next output.println(continued) - buf append "\n" + buf append System.lineSeparator() buf append continued.drop(continuationPrompt.length) } buf.toString @@ -49,7 +49,7 @@ class TestREPL(script: String) extends REPL { out.close() val printed = out.toString val transcript = printed.drop(printed.indexOf(config.prompt)) - if (transcript.toString != script) { + if (transcript.toString.lines.toList != script.lines.toList) { println("input differs from transcript:") println(transcript) assert(false) -- cgit v1.2.3 From 6bce106fea7ce10eefc864a6e7c1351675065880 Mon Sep 17 00:00:00 2001 From: Martijn Hoekstra Date: Fri, 26 Aug 2016 12:51:07 +0200 Subject: force UTF-8 for slurp and write --- test/test/CompilerTest.scala | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/test/CompilerTest.scala b/test/test/CompilerTest.scala index b56b910bf..d0e4b9a52 100644 --- a/test/test/CompilerTest.scala +++ b/test/test/CompilerTest.scala @@ -449,10 +449,36 @@ abstract class CompilerTest { /** Recursively copy over source files and directories, excluding extensions * that aren't in extensionsToCopy. */ private def recCopyFiles(sourceFile: Path, dest: Path): Unit = { - processFileDir(sourceFile, { sf => + def copyfile(file: SFile, bytewise: Boolean): Unit = { + if (bytewise) { + val in = file.inputStream() + val out = SFile(dest).outputStream() + val buffer = new Array[Byte](1024) + def loop(available: Int):Unit = { + if (available < 0) {()} + else { + out.write(buffer, 0, available) + val read = in.read(buffer) + loop(read) + } + } + loop(0) + in.close() + out.close() + } else { + try { + SFile(dest)(scala.io.Codec.UTF8).writeAll((s"/* !!!!! WARNING: DO NOT MODIFY. Original is at: $file !!!!! */").replace("\\", "/"), file.slurp("UTF-8")) + } catch { + case unmappable: java.nio.charset.MalformedInputException => + copyfile(file, true) //there are bytes that can't be mapped with UTF-8. Bail and just do a straight byte-wise copy without the warning header. + } + } + } + + processFileDir(sourceFile, { sf => if (extensionsToCopy.contains(sf.extension)) { dest.parent.jfile.mkdirs - dest.toFile.writeAll(s"/* !!!!! WARNING: DO NOT MODIFY. Original is at: $sf !!!!! */", sf.slurp) + copyfile(sf, false) } else { log(s"WARNING: ignoring $sf") } -- cgit v1.2.3 From 32819e2edc88dd06095704c04ed9c2dd0603386f Mon Sep 17 00:00:00 2001 From: Martijn Hoekstra Date: Sat, 3 Sep 2016 12:10:53 +0200 Subject: honor -encoding compiler flag and defaults rename test/pos/valueclasses to pos_valueclasses tests/pos/valueclasses generates a valueclasses.flags file in /tests/partest-generated/pos that conflicts with the valueClasses.flags file that tests/neg/valueClasses.scala tries to create --- .gitattributes | 23 +++++---- dottydoc/test/BaseTest.scala | 2 +- project/Build.scala | 2 +- src/dotty/tools/dotc/Run.scala | 6 ++- src/dotty/tools/dotc/config/Settings.scala | 2 + src/dotty/tools/dotc/util/SourceFile.scala | 7 +-- test/dotc/tests.scala | 10 ++-- test/test/CompilerTest.scala | 8 +-- test/test/DottyTest.scala | 1 + test/test/ParserTest.scala | 3 +- test/test/ScannerTest.scala | 5 +- tests/pos-special/utf16encoded.scala | Bin 0 -> 324 bytes tests/pos-special/utf8encoded.scala | 8 +++ .../pos/pos_valueclasses/nullAsInstanceOfVC.scala | 29 +++++++++++ tests/pos/pos_valueclasses/optmatch.scala | 35 +++++++++++++ tests/pos/pos_valueclasses/paramlists.scala | 37 +++++++++++++ tests/pos/pos_valueclasses/privatethisparam.scala | 18 +++++++ tests/pos/pos_valueclasses/t5667.scala | 6 +++ tests/pos/pos_valueclasses/t5853.scala | 57 +++++++++++++++++++++ tests/pos/pos_valueclasses/t5953.scala | 18 +++++++ tests/pos/pos_valueclasses/t6029.scala | 5 ++ tests/pos/pos_valueclasses/t6034.scala | 3 ++ tests/pos/pos_valueclasses/t6215.scala | 3 ++ tests/pos/pos_valueclasses/t6260.scala | 19 +++++++ tests/pos/pos_valueclasses/t6260a.scala | 17 ++++++ tests/pos/pos_valueclasses/t6260b.scala | 5 ++ tests/pos/pos_valueclasses/t6358.scala | 8 +++ tests/pos/pos_valueclasses/t6358_2.scala | 8 +++ .../t6601/PrivateValueClass_1.scala | 3 ++ .../t6601/UsePrivateValueClass_2.scala | 12 +++++ tests/pos/pos_valueclasses/t6651.scala | 35 +++++++++++++ tests/pos/pos_valueclasses/t7818.scala | 12 +++++ tests/pos/pos_valueclasses/t8011.scala | 10 ++++ tests/pos/pos_valueclasses/t9298/JUse.java | 7 +++ tests/pos/pos_valueclasses/t9298/Meter.scala | 3 ++ tests/pos/pos_valueclasses/t9298/Use.scala | 9 ++++ .../value-class-override-no-spec.flags | 1 + .../value-class-override-no-spec.scala | 11 ++++ .../value-class-override-spec.scala | 11 ++++ tests/pos/pos_valueclasses/xlint1.flags | 1 + tests/pos/pos_valueclasses/xlint1.scala | 15 ++++++ tests/pos/valueclasses/nullAsInstanceOfVC.scala | 29 ----------- tests/pos/valueclasses/optmatch.scala | 35 ------------- tests/pos/valueclasses/paramlists.scala | 37 ------------- tests/pos/valueclasses/privatethisparam.scala | 18 ------- tests/pos/valueclasses/t5667.scala | 6 --- tests/pos/valueclasses/t5853.scala | 57 --------------------- tests/pos/valueclasses/t5953.scala | 18 ------- tests/pos/valueclasses/t6029.scala | 5 -- tests/pos/valueclasses/t6034.scala | 3 -- tests/pos/valueclasses/t6215.scala | 3 -- tests/pos/valueclasses/t6260.scala | 19 ------- tests/pos/valueclasses/t6260a.scala | 17 ------ tests/pos/valueclasses/t6260b.scala | 5 -- tests/pos/valueclasses/t6358.scala | 8 --- tests/pos/valueclasses/t6358_2.scala | 8 --- .../valueclasses/t6601/PrivateValueClass_1.scala | 3 -- .../t6601/UsePrivateValueClass_2.scala | 12 ----- tests/pos/valueclasses/t6651.scala | 35 ------------- tests/pos/valueclasses/t7818.scala | 12 ----- tests/pos/valueclasses/t8011.scala | 10 ---- tests/pos/valueclasses/t9298/JUse.java | 7 --- tests/pos/valueclasses/t9298/Meter.scala | 3 -- tests/pos/valueclasses/t9298/Use.scala | 9 ---- .../value-class-override-no-spec.flags | 1 - .../value-class-override-no-spec.scala | 11 ---- .../valueclasses/value-class-override-spec.scala | 11 ---- tests/pos/valueclasses/xlint1.flags | 1 - tests/pos/valueclasses/xlint1.scala | 15 ------ 69 files changed, 448 insertions(+), 425 deletions(-) create mode 100644 tests/pos-special/utf16encoded.scala create mode 100644 tests/pos-special/utf8encoded.scala create mode 100644 tests/pos/pos_valueclasses/nullAsInstanceOfVC.scala create mode 100644 tests/pos/pos_valueclasses/optmatch.scala create mode 100644 tests/pos/pos_valueclasses/paramlists.scala create mode 100644 tests/pos/pos_valueclasses/privatethisparam.scala create mode 100644 tests/pos/pos_valueclasses/t5667.scala create mode 100644 tests/pos/pos_valueclasses/t5853.scala create mode 100644 tests/pos/pos_valueclasses/t5953.scala create mode 100644 tests/pos/pos_valueclasses/t6029.scala create mode 100644 tests/pos/pos_valueclasses/t6034.scala create mode 100644 tests/pos/pos_valueclasses/t6215.scala create mode 100644 tests/pos/pos_valueclasses/t6260.scala create mode 100644 tests/pos/pos_valueclasses/t6260a.scala create mode 100644 tests/pos/pos_valueclasses/t6260b.scala create mode 100644 tests/pos/pos_valueclasses/t6358.scala create mode 100644 tests/pos/pos_valueclasses/t6358_2.scala create mode 100644 tests/pos/pos_valueclasses/t6601/PrivateValueClass_1.scala create mode 100644 tests/pos/pos_valueclasses/t6601/UsePrivateValueClass_2.scala create mode 100644 tests/pos/pos_valueclasses/t6651.scala create mode 100644 tests/pos/pos_valueclasses/t7818.scala create mode 100644 tests/pos/pos_valueclasses/t8011.scala create mode 100644 tests/pos/pos_valueclasses/t9298/JUse.java create mode 100644 tests/pos/pos_valueclasses/t9298/Meter.scala create mode 100644 tests/pos/pos_valueclasses/t9298/Use.scala create mode 100644 tests/pos/pos_valueclasses/value-class-override-no-spec.flags create mode 100644 tests/pos/pos_valueclasses/value-class-override-no-spec.scala create mode 100644 tests/pos/pos_valueclasses/value-class-override-spec.scala create mode 100644 tests/pos/pos_valueclasses/xlint1.flags create mode 100644 tests/pos/pos_valueclasses/xlint1.scala delete mode 100644 tests/pos/valueclasses/nullAsInstanceOfVC.scala delete mode 100644 tests/pos/valueclasses/optmatch.scala delete mode 100644 tests/pos/valueclasses/paramlists.scala delete mode 100644 tests/pos/valueclasses/privatethisparam.scala delete mode 100644 tests/pos/valueclasses/t5667.scala delete mode 100644 tests/pos/valueclasses/t5853.scala delete mode 100644 tests/pos/valueclasses/t5953.scala delete mode 100644 tests/pos/valueclasses/t6029.scala delete mode 100644 tests/pos/valueclasses/t6034.scala delete mode 100644 tests/pos/valueclasses/t6215.scala delete mode 100644 tests/pos/valueclasses/t6260.scala delete mode 100644 tests/pos/valueclasses/t6260a.scala delete mode 100644 tests/pos/valueclasses/t6260b.scala delete mode 100644 tests/pos/valueclasses/t6358.scala delete mode 100644 tests/pos/valueclasses/t6358_2.scala delete mode 100644 tests/pos/valueclasses/t6601/PrivateValueClass_1.scala delete mode 100644 tests/pos/valueclasses/t6601/UsePrivateValueClass_2.scala delete mode 100644 tests/pos/valueclasses/t6651.scala delete mode 100644 tests/pos/valueclasses/t7818.scala delete mode 100644 tests/pos/valueclasses/t8011.scala delete mode 100644 tests/pos/valueclasses/t9298/JUse.java delete mode 100644 tests/pos/valueclasses/t9298/Meter.scala delete mode 100644 tests/pos/valueclasses/t9298/Use.scala delete mode 100644 tests/pos/valueclasses/value-class-override-no-spec.flags delete mode 100644 tests/pos/valueclasses/value-class-override-no-spec.scala delete mode 100644 tests/pos/valueclasses/value-class-override-spec.scala delete mode 100644 tests/pos/valueclasses/xlint1.flags delete mode 100644 tests/pos/valueclasses/xlint1.scala (limited to 'test') diff --git a/.gitattributes b/.gitattributes index d9d8b125c..a4689a686 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,15 +1,16 @@ # These files are text and should be normalized (convert crlf => lf) -*.c text -*.check text -*.css text -*.html text -*.java text -*.js text -*.sbt text -*.scala text -*.sh text -*.txt text -*.xml text + +*.c text eol=lf +*.check text eol=lf +*.css text eol=lf +*.html text eol=lf +*.java text eol=lf +*.js text eol=lf +*.sbt text eol=lf +*.scala text eol=lf +*.sh text eol=lf +*.txt text eol=lf +*.xml text eol=lf # Windows-specific files get windows endings *.bat eol=crlf diff --git a/dottydoc/test/BaseTest.scala b/dottydoc/test/BaseTest.scala index 2233d03c8..808387a44 100644 --- a/dottydoc/test/BaseTest.scala +++ b/dottydoc/test/BaseTest.scala @@ -12,7 +12,7 @@ import model.Package trait DottyTest { dotty.tools.dotc.parsing.Scanners // initialize keywords - implicit var ctx: FreshContext = { + implicit val ctx: FreshContext = { val base = new ContextBase import base.settings._ val ctx = base.initialCtx.fresh diff --git a/project/Build.scala b/project/Build.scala index 1412556a9..88ee7dca7 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -40,7 +40,7 @@ object DottyBuild extends Build { homepage in Global := Some(url("https://github.com/lampepfl/dotty")), // scalac options - scalacOptions in Global ++= Seq("-feature", "-deprecation", "-language:existentials,higherKinds,implicitConversions"), + scalacOptions in Global ++= Seq("-feature", "-deprecation", "-encoding", "UTF8", "-language:existentials,higherKinds,implicitConversions"), javacOptions in Global ++= Seq("-Xlint:unchecked", "-Xlint:deprecation") ) diff --git a/src/dotty/tools/dotc/Run.scala b/src/dotty/tools/dotc/Run.scala index 1a26748bf..fa69530b5 100644 --- a/src/dotty/tools/dotc/Run.scala +++ b/src/dotty/tools/dotc/Run.scala @@ -9,6 +9,7 @@ import Phases._ import Decorators._ import dotty.tools.dotc.transform.TreeTransforms.TreeTransformer import io.PlainFile +import scala.io.Codec import util._ import reporting.Reporter import transform.TreeChecker @@ -28,8 +29,9 @@ class Run(comp: Compiler)(implicit ctx: Context) { var units: List[CompilationUnit] = _ def getSource(fileName: String): SourceFile = { + val encoding = ctx.settings.encoding.value val f = new PlainFile(fileName) - if (f.exists) new SourceFile(f) + if (f.exists) new SourceFile(f, Codec(encoding)) else { ctx.error(s"not found: $fileName") NoSource @@ -113,7 +115,7 @@ class Run(comp: Compiler)(implicit ctx: Context) { val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8")) // buffering is still advised by javadoc writer.write(sourceCode) writer.close() - compileSources(List(new SourceFile(virtualFile))) + compileSources(List(new SourceFile(virtualFile, Codec.UTF8))) } /** The context created for this run */ diff --git a/src/dotty/tools/dotc/config/Settings.scala b/src/dotty/tools/dotc/config/Settings.scala index 73df4e1ec..cffa047fe 100644 --- a/src/dotty/tools/dotc/config/Settings.scala +++ b/src/dotty/tools/dotc/config/Settings.scala @@ -25,6 +25,8 @@ object Settings { private var values = ArrayBuffer(initialValues: _*) private var _wasRead: Boolean = false + override def toString = s"SettingsState(values: ${values.toList})" + def value(idx: Int): Any = { _wasRead = true values(idx) diff --git a/src/dotty/tools/dotc/util/SourceFile.scala b/src/dotty/tools/dotc/util/SourceFile.scala index 6b547203e..344bc253a 100644 --- a/src/dotty/tools/dotc/util/SourceFile.scala +++ b/src/dotty/tools/dotc/util/SourceFile.scala @@ -10,6 +10,7 @@ import java.io.IOException import Chars._ import ScriptSourceFile._ import Positions._ +import scala.io.Codec import java.util.Optional @@ -36,9 +37,9 @@ object ScriptSourceFile { case class SourceFile(file: AbstractFile, content: Array[Char]) extends interfaces.SourceFile { - def this(_file: AbstractFile) = this(_file, _file.toCharArray) - def this(sourceName: String, cs: Seq[Char]) = this(new VirtualFile(sourceName), cs.toArray) - def this(file: AbstractFile, cs: Seq[Char]) = this(file, cs.toArray) + def this(_file: AbstractFile, codec: Codec) = this(_file, new String(_file.toByteArray, codec.charSet).toCharArray) + def this(sourceName: String, cs: Seq[Char]) = this(new VirtualFile(sourceName), cs.toArray) + def this(file: AbstractFile, cs: Seq[Char]) = this(file, cs.toArray) /** Tab increment; can be overridden */ def tabInc = 8 diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index 9f95a30c1..c4d8085f5 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -23,8 +23,7 @@ class tests extends CompilerTest { val defaultOutputDir = "./out/" implicit val defaultOptions = noCheckOptions ++ List( - "-Yno-deep-subtypes", "-Yno-double-bindings", "-Yforce-sbt-phases", - "-d", defaultOutputDir) ++ { + "-Yno-deep-subtypes", "-Yno-double-bindings", "-Yforce-sbt-phases", "-d", defaultOutputDir) ++ { if (isRunByJenkins) List("-Ycheck:tailrec,resolveSuper,mixin,restoreScopes,labelDef") // should be Ycheck:all, but #725 else List("-Ycheck:tailrec,resolveSuper,mixin,restoreScopes,labelDef") } @@ -38,6 +37,9 @@ class tests extends CompilerTest { val allowDoubleBindings = defaultOptions diff List("-Yno-double-bindings") val scala2mode = List("-language:Scala2") + val explicitUTF8 = List("-encoding", "UTF8") + val explicitUTF16 = List("-encoding", "UTF16") + val testsDir = "./tests/" val posDir = testsDir + "pos/" val posSpecialDir = testsDir + "pos-special/" @@ -95,7 +97,7 @@ class tests extends CompilerTest { @Test def pos_overloadedAccess = compileFile(posDir, "overloadedAccess", twice) @Test def pos_approximateUnion = compileFile(posDir, "approximateUnion", twice) @Test def pos_tailcall = compileDir(posDir, "tailcall", twice) - @Test def pos_valueclasses = compileFiles(posDir + "valueclasses/", twice) + @Test def pos_valueclasses = compileFiles(posDir + "pos_valueclasses/", twice) @Test def pos_nullarify = compileFile(posDir, "nullarify", args = "-Ycheck:nullarify" :: Nil) @Test def pos_subtyping = compileFile(posDir, "subtyping", twice) @Test def pos_packageObj = compileFile(posDir, "i0239", twice) @@ -118,6 +120,8 @@ class tests extends CompilerTest { compileFile(posSpecialDir, "spec-t5545/S_1") compileFile(posSpecialDir, "spec-t5545/S_2") } + @Test def pos_utf8 = compileFile(posSpecialDir, "utf8encoded", explicitUTF8) + @Test def pos_utf16 = compileFile(posSpecialDir, "utf16encoded", explicitUTF16) @Test def new_all = compileFiles(newDir, twice) @Test def repl_all = replFiles(replDir) diff --git a/test/test/CompilerTest.scala b/test/test/CompilerTest.scala index d0e4b9a52..6bd5f7030 100644 --- a/test/test/CompilerTest.scala +++ b/test/test/CompilerTest.scala @@ -413,7 +413,8 @@ abstract class CompilerTest { val flags = oldFlags.map(f => if (f == oldOutput) partestOutput else f) ++ List(s"-classpath $partestOutput") // Required for separate compilation tests - getExisting(dest).isDifferent(source, flags, nerr) match { + val difference = getExisting(dest).isDifferent(source, flags, nerr) + difference match { case NotExists => copyFiles(source, dest, partestOutput, flags, nerr, kind) case ExistsSame => // nothing else to do case ExistsDifferent => @@ -449,6 +450,7 @@ abstract class CompilerTest { /** Recursively copy over source files and directories, excluding extensions * that aren't in extensionsToCopy. */ private def recCopyFiles(sourceFile: Path, dest: Path): Unit = { + def copyfile(file: SFile, bytewise: Boolean): Unit = { if (bytewise) { val in = file.inputStream() @@ -490,7 +492,7 @@ abstract class CompilerTest { /** Reads the existing files for the given test source if any. */ private def getExisting(dest: Path): ExistingFiles = { - val content: Option[Option[String]] = processFileDir(dest, f => f.safeSlurp, d => Some("")) + val content: Option[Option[String]] = processFileDir(dest, f => try Some(f.slurp("UTF8")) catch {case io: java.io.IOException => Some(io.toString())}, d => Some("")) if (content.isDefined && content.get.isDefined) { val flags = (dest changeExtension "flags").toFile.safeSlurp val nerr = (dest changeExtension "nerr").toFile.safeSlurp @@ -504,7 +506,7 @@ abstract class CompilerTest { if (!genSrc.isDefined) { NotExists } else { - val source = processFileDir(sourceFile, { f => f.safeSlurp }, { d => Some("") }, + val source = processFileDir(sourceFile, { f => try Some(f.slurp("UTF8")) catch {case _: java.io.IOException => None} }, { d => Some("") }, Some("DPCompilerTest sourceFile doesn't exist: " + sourceFile)).get if (source == genSrc) { nerr match { diff --git a/test/test/DottyTest.scala b/test/test/DottyTest.scala index 15d82c208..4b767b318 100644 --- a/test/test/DottyTest.scala +++ b/test/test/DottyTest.scala @@ -23,6 +23,7 @@ class DottyTest /*extends ContextEscapeDetection*/ { import base.settings._ val ctx = base.initialCtx.fresh base.initialize()(ctx) + ctx.setSetting(ctx.settings.encoding, "UTF8") ctx } /* diff --git a/test/test/ParserTest.scala b/test/test/ParserTest.scala index 524be272d..f66dbf55d 100644 --- a/test/test/ParserTest.scala +++ b/test/test/ParserTest.scala @@ -4,6 +4,7 @@ import scala.reflect.io._ import dotty.tools.dotc.util._ import dotty.tools.dotc.core._ import dotty.tools.dotc.parsing._ +import scala.io.Codec import Tokens._, Parsers._ import dotty.tools.dotc.ast.untpd._ import org.junit.Test @@ -23,7 +24,7 @@ class ParserTest extends DottyTest { def parse(file: PlainFile): Tree = { //println("***** parsing " + file) - val source = new SourceFile(file) + val source = new SourceFile(file, Codec.UTF8) val parser = new Parser(source) val tree = parser.parse() parsed += 1 diff --git a/test/test/ScannerTest.scala b/test/test/ScannerTest.scala index f8f09ff6f..5ff9bba0c 100644 --- a/test/test/ScannerTest.scala +++ b/test/test/ScannerTest.scala @@ -1,6 +1,7 @@ package test import scala.reflect.io._ +import scala.io.Codec import dotty.tools.dotc.util._ import dotty.tools.dotc.parsing._ import Tokens._, Scanners._ @@ -16,8 +17,8 @@ class ScannerTest extends DottyTest { def scan(name: String): Unit = scan(new PlainFile(name)) def scan(file: PlainFile): Unit = { - println("***** scanning " + file) - val source = new SourceFile(file) + //println("***** scanning " + file) + val source = new SourceFile(file, Codec.UTF8) val scanner = new Scanner(source) var i = 0 while (scanner.token != EOF) { diff --git a/tests/pos-special/utf16encoded.scala b/tests/pos-special/utf16encoded.scala new file mode 100644 index 000000000..d77529f19 Binary files /dev/null and b/tests/pos-special/utf16encoded.scala differ diff --git a/tests/pos-special/utf8encoded.scala b/tests/pos-special/utf8encoded.scala new file mode 100644 index 000000000..6eac24acd --- /dev/null +++ b/tests/pos-special/utf8encoded.scala @@ -0,0 +1,8 @@ +//this file is saved as UTF-8 +object Test { + def main(args: Array[String]): Unit = { + val testchar = '⇒' + println(testchar == '\u21D2') + } + +} \ No newline at end of file diff --git a/tests/pos/pos_valueclasses/nullAsInstanceOfVC.scala b/tests/pos/pos_valueclasses/nullAsInstanceOfVC.scala new file mode 100644 index 000000000..43af839ec --- /dev/null +++ b/tests/pos/pos_valueclasses/nullAsInstanceOfVC.scala @@ -0,0 +1,29 @@ +package nullAsInstanceOfVC + +// These issues were originally reported in SI-5866 and SI-8097 +// FIXME: Make this a run test once we have run tests. + +object VCNull { + case class Foo(d: Double) extends AnyVal { + override def toString = s"Foo($d)" + } + case class Bar(s: String) extends AnyVal { + override def toString = s"Bar($s)" + } + + def testDirect(): Unit = { + val fooDirect: Foo = null.asInstanceOf[Foo] + val barDirect: Bar = null.asInstanceOf[Bar] + } + + def testIndirect(): Unit = { + val fooIndirect: Foo = { val n: Any = null; n.asInstanceOf[Foo] } + val barIndirect: Bar = { val n: Any = null; n.asInstanceOf[Bar] } + } + + def nullOf[T]: T = null.asInstanceOf[T] + def testGeneric(): Unit = { + val fooGeneric: Foo = nullOf[Foo] + val barGeneric: Bar = nullOf[Bar] + } +} diff --git a/tests/pos/pos_valueclasses/optmatch.scala b/tests/pos/pos_valueclasses/optmatch.scala new file mode 100644 index 000000000..a7995a455 --- /dev/null +++ b/tests/pos/pos_valueclasses/optmatch.scala @@ -0,0 +1,35 @@ +package optmatch + +// final case class NonZeroLong(value: Long) extends AnyVal { +// def get: Long = value +// def isEmpty: Boolean = get == 0l +// } + +class NonZeroLong(val value: Long) extends AnyVal { + def get: Long = value + def isDefined: Boolean = get != 0l +} +object NonZeroLong { + def unapply(value: Long): NonZeroLong = new NonZeroLong(value) +} + + +object Foo { + def unapply(x: Int): NonZeroLong = new NonZeroLong(1L << x) + // public long unapply(int); + // 0: lconst_1 + // 1: iload_1 + // 2: lshl + // 3: lreturn +} + +object Test { + def f(x: Int): Int = x match { + case Foo(1024l) => 1 + case _ => 2 + } + def main(args: Array[String]): Unit = { + println(f(10)) + println(f(11)) + } +} diff --git a/tests/pos/pos_valueclasses/paramlists.scala b/tests/pos/pos_valueclasses/paramlists.scala new file mode 100644 index 000000000..f390a44e0 --- /dev/null +++ b/tests/pos/pos_valueclasses/paramlists.scala @@ -0,0 +1,37 @@ +package paramlists + +class Meter[T](val x: T) extends AnyVal { + def zero: T = x + def zero2[M >: T]: M = x + def one(): T = x + def one2[M >: T](): M = x + def one3(x: T): T = x + def one4[M >: T](x: M): M = x + def two(x: T)(y: T): T = y + def two2[M >: T](x: T)(y: M): M = y +} + +object Test { + def test: Unit = { + val m1 = new Meter(1) + m1.zero + m1.zero2 + m1.one + m1.one2 + m1.one3(10) + m1.two(11)(12) + m1.two2(11)(12) + + { + import m1._ + + zero + zero2 + one + one2 + one3(10) + two(11)(12) + two2(11)(12) + } + } +} diff --git a/tests/pos/pos_valueclasses/privatethisparam.scala b/tests/pos/pos_valueclasses/privatethisparam.scala new file mode 100644 index 000000000..77ca9851c --- /dev/null +++ b/tests/pos/pos_valueclasses/privatethisparam.scala @@ -0,0 +1,18 @@ +package privatethisparam + +class Meter[T](x: T) extends AnyVal { + def zero: T = x +} + +class Meter2(private[this] val x: Int) extends AnyVal { + def foo = x +} + +object Test { + def bar = new Meter2(42) + def useZero = new Meter(5).zero + def test: Unit = { + val m1 = new Meter(1) + m1.zero + } +} \ No newline at end of file diff --git a/tests/pos/pos_valueclasses/t5667.scala b/tests/pos/pos_valueclasses/t5667.scala new file mode 100644 index 000000000..80efb181b --- /dev/null +++ b/tests/pos/pos_valueclasses/t5667.scala @@ -0,0 +1,6 @@ +package t5667 + +object Main { + implicit class C(val s: String) extends AnyVal + implicit class C2(val s: String) extends AnyRef +} diff --git a/tests/pos/pos_valueclasses/t5853.scala b/tests/pos/pos_valueclasses/t5853.scala new file mode 100644 index 000000000..82ac9dd1d --- /dev/null +++ b/tests/pos/pos_valueclasses/t5853.scala @@ -0,0 +1,57 @@ +package t5853 + + + + + + + + +final class C(val x: Int) extends AnyVal { + def ppp[@specialized(Int) T](y: T) = () +} + + +class Foo { + def f = new C(1) ppp 2 +} + + +/* Original SI-5853 test-case. */ + +object Bippy { + implicit final class C(val x: Int) extends AnyVal { + def +++[@specialized T](y: T) = () + } + def f = 1 +++ 2 +} + + +/* Few more examples. */ + +final class C2(val x: Int) extends AnyVal { + def +++[@specialized(Int) T](y: T) = () +} + + +class Foo2 { + def f = new C2(1) +++ 2 +} + + +object Arrow { + implicit final class ArrowAssoc[A](val __leftOfArrow: A) extends AnyVal { + @inline def ->>[B](y: B): Tuple2[A, B] = Tuple2(__leftOfArrow, y) + } + + def foo = 1 ->> 2 +} + + +object SpecArrow { + implicit final class ArrowAssoc[A](val __leftOfArrow: A) extends AnyVal { + @inline def ->> [@specialized(Int) B](y: B): Tuple2[A, B] = Tuple2(__leftOfArrow, y) + } + + def foo = 1 ->> 2 +} diff --git a/tests/pos/pos_valueclasses/t5953.scala b/tests/pos/pos_valueclasses/t5953.scala new file mode 100644 index 000000000..669fac7df --- /dev/null +++ b/tests/pos/pos_valueclasses/t5953.scala @@ -0,0 +1,18 @@ +package t5953 + +import scala.collection.{ mutable, immutable, generic, GenTraversableOnce } + +package object foo { + @inline implicit class TravOps[A, CC[A] <: GenTraversableOnce[A]](val coll: CC[A]) extends AnyVal { + def build[CC2[X]](implicit cbf: generic.CanBuildFrom[Nothing, A, CC2[A]]): CC2[A] = { + cbf() ++= coll.toIterator result + } + } +} + +package foo { + object Test { + def f1[T](xs: Traversable[T]) = xs.to[immutable.Vector] + def f2[T](xs: Traversable[T]) = xs.build[immutable.Vector] + } +} diff --git a/tests/pos/pos_valueclasses/t6029.scala b/tests/pos/pos_valueclasses/t6029.scala new file mode 100644 index 000000000..13f8f8830 --- /dev/null +++ b/tests/pos/pos_valueclasses/t6029.scala @@ -0,0 +1,5 @@ +package t6029 + +final case class V[A](x: A) extends AnyVal { + def flatMap[B](f: A => V[B]) = if (true) this else f(x) +} diff --git a/tests/pos/pos_valueclasses/t6034.scala b/tests/pos/pos_valueclasses/t6034.scala new file mode 100644 index 000000000..8e2fb625c --- /dev/null +++ b/tests/pos/pos_valueclasses/t6034.scala @@ -0,0 +1,3 @@ +package t6034 + +final class OptPlus[+A](val x: A) extends AnyVal { } diff --git a/tests/pos/pos_valueclasses/t6215.scala b/tests/pos/pos_valueclasses/t6215.scala new file mode 100644 index 000000000..579503e6c --- /dev/null +++ b/tests/pos/pos_valueclasses/t6215.scala @@ -0,0 +1,3 @@ +package t6215 + +class Foo(val v: String) extends AnyVal { private def len = v.length ; def f = len } diff --git a/tests/pos/pos_valueclasses/t6260.scala b/tests/pos/pos_valueclasses/t6260.scala new file mode 100644 index 000000000..675c3c16a --- /dev/null +++ b/tests/pos/pos_valueclasses/t6260.scala @@ -0,0 +1,19 @@ +package t6260 + +class Box[X](val x: X) extends AnyVal { + def map[Y](f: X => Y): Box[Y] = + ((bx: Box[X]) => new Box(f(bx.x)))(this) +} + +object Test { + def map2[X, Y](self: Box[X], f: X => Y): Box[Y] = + ((bx: Box[X]) => new Box(f(bx.x)))(self) + + def main(args: Array[String]): Unit = { + val f = (x: Int) => x + 1 + val g = (x: String) => x + x + + map2(new Box(42), f) + new Box("abc") map g + } +} diff --git a/tests/pos/pos_valueclasses/t6260a.scala b/tests/pos/pos_valueclasses/t6260a.scala new file mode 100644 index 000000000..e29f10452 --- /dev/null +++ b/tests/pos/pos_valueclasses/t6260a.scala @@ -0,0 +1,17 @@ +package t6260a + +final class Option[+A](val value: A) extends AnyVal + +// Was: sandbox/test.scala:21: error: bridge generated for member method f: ()Option[A] in class Bar +// which overrides method f: ()Option[A] in class Foo" +abstract class Foo[A] { def f(): Option[A] } + class Bar[A] extends Foo[A] { def f(): Option[A] = ??? } + +// User reported this as erroneous but I couldn't reproduce with 2.10.{0,1,2,3} +// https://issues.scala-lang.org/browse/SI-6260?focusedCommentId=64764&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-64764 +// I suspect he whittled down the example too far. +class Wrapper(val value: Int) extends AnyVal +abstract class Test { def check(the: Wrapper): Boolean } +object T { + new Test { def check(the: Wrapper) = true } +} diff --git a/tests/pos/pos_valueclasses/t6260b.scala b/tests/pos/pos_valueclasses/t6260b.scala new file mode 100644 index 000000000..fb9a2961b --- /dev/null +++ b/tests/pos/pos_valueclasses/t6260b.scala @@ -0,0 +1,5 @@ +package t6260b + + +class X(val value: Object) extends AnyVal { def or(alt: => X): X = this } +class Y { def f = new X("") or new X("") } diff --git a/tests/pos/pos_valueclasses/t6358.scala b/tests/pos/pos_valueclasses/t6358.scala new file mode 100644 index 000000000..291ae2e9e --- /dev/null +++ b/tests/pos/pos_valueclasses/t6358.scala @@ -0,0 +1,8 @@ +package t6358 + +class L(val t: Int) extends AnyVal { + def lazyString = { + lazy val x = t.toString + () => x + } +} diff --git a/tests/pos/pos_valueclasses/t6358_2.scala b/tests/pos/pos_valueclasses/t6358_2.scala new file mode 100644 index 000000000..effac505a --- /dev/null +++ b/tests/pos/pos_valueclasses/t6358_2.scala @@ -0,0 +1,8 @@ +package t6358_2 + +class Y[T](val i: Option[T]) extends AnyVal { + def q: List[T] = { + lazy val e: List[T] = i.toList + e + } +} diff --git a/tests/pos/pos_valueclasses/t6601/PrivateValueClass_1.scala b/tests/pos/pos_valueclasses/t6601/PrivateValueClass_1.scala new file mode 100644 index 000000000..fc6f3e422 --- /dev/null +++ b/tests/pos/pos_valueclasses/t6601/PrivateValueClass_1.scala @@ -0,0 +1,3 @@ +package t6601 + +class V private (val a: Any) extends AnyVal diff --git a/tests/pos/pos_valueclasses/t6601/UsePrivateValueClass_2.scala b/tests/pos/pos_valueclasses/t6601/UsePrivateValueClass_2.scala new file mode 100644 index 000000000..acd0dbef9 --- /dev/null +++ b/tests/pos/pos_valueclasses/t6601/UsePrivateValueClass_2.scala @@ -0,0 +1,12 @@ +package t6601 + +object Test { + // After the first attempt to make seprately compiled value + // classes respect the privacy of constructors, we got: + // + // exception when typing v.a().==(v.a())/class scala.reflect.internal.Trees$Apply + // constructor V in class V cannot be accessed in object Test in file test/files/pos/t6601/UsePrivateValueClass_2.scala + // scala.reflect.internal.Types$TypeError: constructor V in class V cannot be accessed in object Test + def foo(v: V) = v.a == v.a + def bar(v: V) = v == v +} diff --git a/tests/pos/pos_valueclasses/t6651.scala b/tests/pos/pos_valueclasses/t6651.scala new file mode 100644 index 000000000..6201b6de3 --- /dev/null +++ b/tests/pos/pos_valueclasses/t6651.scala @@ -0,0 +1,35 @@ +package t6651 + +class YouAreYourself[A <: AnyRef](val you: A) extends AnyVal { + def yourself: you.type = you +} + +object Test { + val s = "" + val s1: s.type = new YouAreYourself[s.type](s).yourself +} + +trait Path { + type Dep <: AnyRef +} + +final class ValueClass[P <: Path](val path: P) extends AnyVal { + import path.Dep + + def apply(dep: Dep)(d2: dep.type, foo: Int): (Dep, d2.type) = (d2, d2) + + // This generates dodgy code; note `ValueClass.this`: + // + // final def bounds$extension[D >: Nothing <: ValueClass.this.path.Dep, + // P >: Nothing <: Path] + // ($this: ValueClass[P]) + // (dep: D) + // (d2: dep.type, foo: Int): (D, d2.type) = scala.Tuple2.apply[D, d2.type](d2, d2); + // + // Nothing crashes down the line, but it certainly doesn't conform to best-practices. + // + // An better alternative would be to add a type parameter for the (singleton) type of + // the wrapped value. + def bounds[D <: Dep](dep: D)(d2: dep.type, foo: Int): (D, d2.type) = (d2, d2) +} + diff --git a/tests/pos/pos_valueclasses/t7818.scala b/tests/pos/pos_valueclasses/t7818.scala new file mode 100644 index 000000000..31f542366 --- /dev/null +++ b/tests/pos/pos_valueclasses/t7818.scala @@ -0,0 +1,12 @@ +package t7818 + +class Observable1[+T](val asJava: JObservable[_ <: T]) extends AnyVal { + private def foo[X](a: JObservable[X]): JObservable[X] = ??? + // was generating a type error as the type of the RHS included an existential + // skolem based on the class type parameter `T`, which did not conform + // to the typer parameter of the extension method into which the RHS is + // transplanted. + def synchronize: Observable1[T] = new Observable1(foo(asJava)) +} + +class JObservable[T] diff --git a/tests/pos/pos_valueclasses/t8011.scala b/tests/pos/pos_valueclasses/t8011.scala new file mode 100644 index 000000000..88b4b53aa --- /dev/null +++ b/tests/pos/pos_valueclasses/t8011.scala @@ -0,0 +1,10 @@ +package t8011 + +class ThingOps1(val x: String) extends AnyVal { + def fn[A]: Any = { + new X[A] { def foo(a: A) = a } + 0 + } +} + +trait X[B] { def foo(a: B): Any } diff --git a/tests/pos/pos_valueclasses/t9298/JUse.java b/tests/pos/pos_valueclasses/t9298/JUse.java new file mode 100644 index 000000000..a872c895a --- /dev/null +++ b/tests/pos/pos_valueclasses/t9298/JUse.java @@ -0,0 +1,7 @@ +package t9298; + +class JUse { + public static Meter jm() { + return new Meter(2); + } +} diff --git a/tests/pos/pos_valueclasses/t9298/Meter.scala b/tests/pos/pos_valueclasses/t9298/Meter.scala new file mode 100644 index 000000000..290b28509 --- /dev/null +++ b/tests/pos/pos_valueclasses/t9298/Meter.scala @@ -0,0 +1,3 @@ +package t9298 + +class Meter(val x: Int) extends AnyVal diff --git a/tests/pos/pos_valueclasses/t9298/Use.scala b/tests/pos/pos_valueclasses/t9298/Use.scala new file mode 100644 index 000000000..41f1fb035 --- /dev/null +++ b/tests/pos/pos_valueclasses/t9298/Use.scala @@ -0,0 +1,9 @@ +// TODO: this should be a run test once we have run tests + +package t9298 + +object Use { + def main(args: Array[String]): Unit = { + val x: Meter = JUse.jm + } +} diff --git a/tests/pos/pos_valueclasses/value-class-override-no-spec.flags b/tests/pos/pos_valueclasses/value-class-override-no-spec.flags new file mode 100644 index 000000000..a7e64e4f0 --- /dev/null +++ b/tests/pos/pos_valueclasses/value-class-override-no-spec.flags @@ -0,0 +1 @@ +-no-specialization \ No newline at end of file diff --git a/tests/pos/pos_valueclasses/value-class-override-no-spec.scala b/tests/pos/pos_valueclasses/value-class-override-no-spec.scala new file mode 100644 index 000000000..058e3e911 --- /dev/null +++ b/tests/pos/pos_valueclasses/value-class-override-no-spec.scala @@ -0,0 +1,11 @@ +package value_class_override_no_spec + +// There are two versions of this tests: one with and one without specialization. +// The bug was only exposed *without* specialization. +trait T extends Any { + def x: Any +} + +final class StringOps(val repr0: String) extends AnyVal with T { + def x = () +} diff --git a/tests/pos/pos_valueclasses/value-class-override-spec.scala b/tests/pos/pos_valueclasses/value-class-override-spec.scala new file mode 100644 index 000000000..c315be8d0 --- /dev/null +++ b/tests/pos/pos_valueclasses/value-class-override-spec.scala @@ -0,0 +1,11 @@ +package value_class_override_spec + +// There are two versions of this tests: one with and one without specialization. +// The bug was only exposed *without* specialization. +trait T extends Any { + def x: Any +} + +final class StringOps(val repr0: String) extends AnyVal with T { + def x = () +} diff --git a/tests/pos/pos_valueclasses/xlint1.flags b/tests/pos/pos_valueclasses/xlint1.flags new file mode 100644 index 000000000..7949c2afa --- /dev/null +++ b/tests/pos/pos_valueclasses/xlint1.flags @@ -0,0 +1 @@ +-Xlint -Xfatal-warnings diff --git a/tests/pos/pos_valueclasses/xlint1.scala b/tests/pos/pos_valueclasses/xlint1.scala new file mode 100644 index 000000000..c2f39f9b3 --- /dev/null +++ b/tests/pos/pos_valueclasses/xlint1.scala @@ -0,0 +1,15 @@ +package xlint1 + +package object foo { + implicit class Bar[T](val x: T) extends AnyVal { + def bippy = 1 + } +} + +package foo { + object Baz { + def main(args: Array[String]): Unit = { + "abc".bippy + } + } +} diff --git a/tests/pos/valueclasses/nullAsInstanceOfVC.scala b/tests/pos/valueclasses/nullAsInstanceOfVC.scala deleted file mode 100644 index 43af839ec..000000000 --- a/tests/pos/valueclasses/nullAsInstanceOfVC.scala +++ /dev/null @@ -1,29 +0,0 @@ -package nullAsInstanceOfVC - -// These issues were originally reported in SI-5866 and SI-8097 -// FIXME: Make this a run test once we have run tests. - -object VCNull { - case class Foo(d: Double) extends AnyVal { - override def toString = s"Foo($d)" - } - case class Bar(s: String) extends AnyVal { - override def toString = s"Bar($s)" - } - - def testDirect(): Unit = { - val fooDirect: Foo = null.asInstanceOf[Foo] - val barDirect: Bar = null.asInstanceOf[Bar] - } - - def testIndirect(): Unit = { - val fooIndirect: Foo = { val n: Any = null; n.asInstanceOf[Foo] } - val barIndirect: Bar = { val n: Any = null; n.asInstanceOf[Bar] } - } - - def nullOf[T]: T = null.asInstanceOf[T] - def testGeneric(): Unit = { - val fooGeneric: Foo = nullOf[Foo] - val barGeneric: Bar = nullOf[Bar] - } -} diff --git a/tests/pos/valueclasses/optmatch.scala b/tests/pos/valueclasses/optmatch.scala deleted file mode 100644 index a7995a455..000000000 --- a/tests/pos/valueclasses/optmatch.scala +++ /dev/null @@ -1,35 +0,0 @@ -package optmatch - -// final case class NonZeroLong(value: Long) extends AnyVal { -// def get: Long = value -// def isEmpty: Boolean = get == 0l -// } - -class NonZeroLong(val value: Long) extends AnyVal { - def get: Long = value - def isDefined: Boolean = get != 0l -} -object NonZeroLong { - def unapply(value: Long): NonZeroLong = new NonZeroLong(value) -} - - -object Foo { - def unapply(x: Int): NonZeroLong = new NonZeroLong(1L << x) - // public long unapply(int); - // 0: lconst_1 - // 1: iload_1 - // 2: lshl - // 3: lreturn -} - -object Test { - def f(x: Int): Int = x match { - case Foo(1024l) => 1 - case _ => 2 - } - def main(args: Array[String]): Unit = { - println(f(10)) - println(f(11)) - } -} diff --git a/tests/pos/valueclasses/paramlists.scala b/tests/pos/valueclasses/paramlists.scala deleted file mode 100644 index f390a44e0..000000000 --- a/tests/pos/valueclasses/paramlists.scala +++ /dev/null @@ -1,37 +0,0 @@ -package paramlists - -class Meter[T](val x: T) extends AnyVal { - def zero: T = x - def zero2[M >: T]: M = x - def one(): T = x - def one2[M >: T](): M = x - def one3(x: T): T = x - def one4[M >: T](x: M): M = x - def two(x: T)(y: T): T = y - def two2[M >: T](x: T)(y: M): M = y -} - -object Test { - def test: Unit = { - val m1 = new Meter(1) - m1.zero - m1.zero2 - m1.one - m1.one2 - m1.one3(10) - m1.two(11)(12) - m1.two2(11)(12) - - { - import m1._ - - zero - zero2 - one - one2 - one3(10) - two(11)(12) - two2(11)(12) - } - } -} diff --git a/tests/pos/valueclasses/privatethisparam.scala b/tests/pos/valueclasses/privatethisparam.scala deleted file mode 100644 index 77ca9851c..000000000 --- a/tests/pos/valueclasses/privatethisparam.scala +++ /dev/null @@ -1,18 +0,0 @@ -package privatethisparam - -class Meter[T](x: T) extends AnyVal { - def zero: T = x -} - -class Meter2(private[this] val x: Int) extends AnyVal { - def foo = x -} - -object Test { - def bar = new Meter2(42) - def useZero = new Meter(5).zero - def test: Unit = { - val m1 = new Meter(1) - m1.zero - } -} \ No newline at end of file diff --git a/tests/pos/valueclasses/t5667.scala b/tests/pos/valueclasses/t5667.scala deleted file mode 100644 index 80efb181b..000000000 --- a/tests/pos/valueclasses/t5667.scala +++ /dev/null @@ -1,6 +0,0 @@ -package t5667 - -object Main { - implicit class C(val s: String) extends AnyVal - implicit class C2(val s: String) extends AnyRef -} diff --git a/tests/pos/valueclasses/t5853.scala b/tests/pos/valueclasses/t5853.scala deleted file mode 100644 index 82ac9dd1d..000000000 --- a/tests/pos/valueclasses/t5853.scala +++ /dev/null @@ -1,57 +0,0 @@ -package t5853 - - - - - - - - -final class C(val x: Int) extends AnyVal { - def ppp[@specialized(Int) T](y: T) = () -} - - -class Foo { - def f = new C(1) ppp 2 -} - - -/* Original SI-5853 test-case. */ - -object Bippy { - implicit final class C(val x: Int) extends AnyVal { - def +++[@specialized T](y: T) = () - } - def f = 1 +++ 2 -} - - -/* Few more examples. */ - -final class C2(val x: Int) extends AnyVal { - def +++[@specialized(Int) T](y: T) = () -} - - -class Foo2 { - def f = new C2(1) +++ 2 -} - - -object Arrow { - implicit final class ArrowAssoc[A](val __leftOfArrow: A) extends AnyVal { - @inline def ->>[B](y: B): Tuple2[A, B] = Tuple2(__leftOfArrow, y) - } - - def foo = 1 ->> 2 -} - - -object SpecArrow { - implicit final class ArrowAssoc[A](val __leftOfArrow: A) extends AnyVal { - @inline def ->> [@specialized(Int) B](y: B): Tuple2[A, B] = Tuple2(__leftOfArrow, y) - } - - def foo = 1 ->> 2 -} diff --git a/tests/pos/valueclasses/t5953.scala b/tests/pos/valueclasses/t5953.scala deleted file mode 100644 index 669fac7df..000000000 --- a/tests/pos/valueclasses/t5953.scala +++ /dev/null @@ -1,18 +0,0 @@ -package t5953 - -import scala.collection.{ mutable, immutable, generic, GenTraversableOnce } - -package object foo { - @inline implicit class TravOps[A, CC[A] <: GenTraversableOnce[A]](val coll: CC[A]) extends AnyVal { - def build[CC2[X]](implicit cbf: generic.CanBuildFrom[Nothing, A, CC2[A]]): CC2[A] = { - cbf() ++= coll.toIterator result - } - } -} - -package foo { - object Test { - def f1[T](xs: Traversable[T]) = xs.to[immutable.Vector] - def f2[T](xs: Traversable[T]) = xs.build[immutable.Vector] - } -} diff --git a/tests/pos/valueclasses/t6029.scala b/tests/pos/valueclasses/t6029.scala deleted file mode 100644 index 13f8f8830..000000000 --- a/tests/pos/valueclasses/t6029.scala +++ /dev/null @@ -1,5 +0,0 @@ -package t6029 - -final case class V[A](x: A) extends AnyVal { - def flatMap[B](f: A => V[B]) = if (true) this else f(x) -} diff --git a/tests/pos/valueclasses/t6034.scala b/tests/pos/valueclasses/t6034.scala deleted file mode 100644 index 8e2fb625c..000000000 --- a/tests/pos/valueclasses/t6034.scala +++ /dev/null @@ -1,3 +0,0 @@ -package t6034 - -final class OptPlus[+A](val x: A) extends AnyVal { } diff --git a/tests/pos/valueclasses/t6215.scala b/tests/pos/valueclasses/t6215.scala deleted file mode 100644 index 579503e6c..000000000 --- a/tests/pos/valueclasses/t6215.scala +++ /dev/null @@ -1,3 +0,0 @@ -package t6215 - -class Foo(val v: String) extends AnyVal { private def len = v.length ; def f = len } diff --git a/tests/pos/valueclasses/t6260.scala b/tests/pos/valueclasses/t6260.scala deleted file mode 100644 index 675c3c16a..000000000 --- a/tests/pos/valueclasses/t6260.scala +++ /dev/null @@ -1,19 +0,0 @@ -package t6260 - -class Box[X](val x: X) extends AnyVal { - def map[Y](f: X => Y): Box[Y] = - ((bx: Box[X]) => new Box(f(bx.x)))(this) -} - -object Test { - def map2[X, Y](self: Box[X], f: X => Y): Box[Y] = - ((bx: Box[X]) => new Box(f(bx.x)))(self) - - def main(args: Array[String]): Unit = { - val f = (x: Int) => x + 1 - val g = (x: String) => x + x - - map2(new Box(42), f) - new Box("abc") map g - } -} diff --git a/tests/pos/valueclasses/t6260a.scala b/tests/pos/valueclasses/t6260a.scala deleted file mode 100644 index e29f10452..000000000 --- a/tests/pos/valueclasses/t6260a.scala +++ /dev/null @@ -1,17 +0,0 @@ -package t6260a - -final class Option[+A](val value: A) extends AnyVal - -// Was: sandbox/test.scala:21: error: bridge generated for member method f: ()Option[A] in class Bar -// which overrides method f: ()Option[A] in class Foo" -abstract class Foo[A] { def f(): Option[A] } - class Bar[A] extends Foo[A] { def f(): Option[A] = ??? } - -// User reported this as erroneous but I couldn't reproduce with 2.10.{0,1,2,3} -// https://issues.scala-lang.org/browse/SI-6260?focusedCommentId=64764&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-64764 -// I suspect he whittled down the example too far. -class Wrapper(val value: Int) extends AnyVal -abstract class Test { def check(the: Wrapper): Boolean } -object T { - new Test { def check(the: Wrapper) = true } -} diff --git a/tests/pos/valueclasses/t6260b.scala b/tests/pos/valueclasses/t6260b.scala deleted file mode 100644 index fb9a2961b..000000000 --- a/tests/pos/valueclasses/t6260b.scala +++ /dev/null @@ -1,5 +0,0 @@ -package t6260b - - -class X(val value: Object) extends AnyVal { def or(alt: => X): X = this } -class Y { def f = new X("") or new X("") } diff --git a/tests/pos/valueclasses/t6358.scala b/tests/pos/valueclasses/t6358.scala deleted file mode 100644 index 291ae2e9e..000000000 --- a/tests/pos/valueclasses/t6358.scala +++ /dev/null @@ -1,8 +0,0 @@ -package t6358 - -class L(val t: Int) extends AnyVal { - def lazyString = { - lazy val x = t.toString - () => x - } -} diff --git a/tests/pos/valueclasses/t6358_2.scala b/tests/pos/valueclasses/t6358_2.scala deleted file mode 100644 index effac505a..000000000 --- a/tests/pos/valueclasses/t6358_2.scala +++ /dev/null @@ -1,8 +0,0 @@ -package t6358_2 - -class Y[T](val i: Option[T]) extends AnyVal { - def q: List[T] = { - lazy val e: List[T] = i.toList - e - } -} diff --git a/tests/pos/valueclasses/t6601/PrivateValueClass_1.scala b/tests/pos/valueclasses/t6601/PrivateValueClass_1.scala deleted file mode 100644 index fc6f3e422..000000000 --- a/tests/pos/valueclasses/t6601/PrivateValueClass_1.scala +++ /dev/null @@ -1,3 +0,0 @@ -package t6601 - -class V private (val a: Any) extends AnyVal diff --git a/tests/pos/valueclasses/t6601/UsePrivateValueClass_2.scala b/tests/pos/valueclasses/t6601/UsePrivateValueClass_2.scala deleted file mode 100644 index acd0dbef9..000000000 --- a/tests/pos/valueclasses/t6601/UsePrivateValueClass_2.scala +++ /dev/null @@ -1,12 +0,0 @@ -package t6601 - -object Test { - // After the first attempt to make seprately compiled value - // classes respect the privacy of constructors, we got: - // - // exception when typing v.a().==(v.a())/class scala.reflect.internal.Trees$Apply - // constructor V in class V cannot be accessed in object Test in file test/files/pos/t6601/UsePrivateValueClass_2.scala - // scala.reflect.internal.Types$TypeError: constructor V in class V cannot be accessed in object Test - def foo(v: V) = v.a == v.a - def bar(v: V) = v == v -} diff --git a/tests/pos/valueclasses/t6651.scala b/tests/pos/valueclasses/t6651.scala deleted file mode 100644 index 6201b6de3..000000000 --- a/tests/pos/valueclasses/t6651.scala +++ /dev/null @@ -1,35 +0,0 @@ -package t6651 - -class YouAreYourself[A <: AnyRef](val you: A) extends AnyVal { - def yourself: you.type = you -} - -object Test { - val s = "" - val s1: s.type = new YouAreYourself[s.type](s).yourself -} - -trait Path { - type Dep <: AnyRef -} - -final class ValueClass[P <: Path](val path: P) extends AnyVal { - import path.Dep - - def apply(dep: Dep)(d2: dep.type, foo: Int): (Dep, d2.type) = (d2, d2) - - // This generates dodgy code; note `ValueClass.this`: - // - // final def bounds$extension[D >: Nothing <: ValueClass.this.path.Dep, - // P >: Nothing <: Path] - // ($this: ValueClass[P]) - // (dep: D) - // (d2: dep.type, foo: Int): (D, d2.type) = scala.Tuple2.apply[D, d2.type](d2, d2); - // - // Nothing crashes down the line, but it certainly doesn't conform to best-practices. - // - // An better alternative would be to add a type parameter for the (singleton) type of - // the wrapped value. - def bounds[D <: Dep](dep: D)(d2: dep.type, foo: Int): (D, d2.type) = (d2, d2) -} - diff --git a/tests/pos/valueclasses/t7818.scala b/tests/pos/valueclasses/t7818.scala deleted file mode 100644 index 31f542366..000000000 --- a/tests/pos/valueclasses/t7818.scala +++ /dev/null @@ -1,12 +0,0 @@ -package t7818 - -class Observable1[+T](val asJava: JObservable[_ <: T]) extends AnyVal { - private def foo[X](a: JObservable[X]): JObservable[X] = ??? - // was generating a type error as the type of the RHS included an existential - // skolem based on the class type parameter `T`, which did not conform - // to the typer parameter of the extension method into which the RHS is - // transplanted. - def synchronize: Observable1[T] = new Observable1(foo(asJava)) -} - -class JObservable[T] diff --git a/tests/pos/valueclasses/t8011.scala b/tests/pos/valueclasses/t8011.scala deleted file mode 100644 index 88b4b53aa..000000000 --- a/tests/pos/valueclasses/t8011.scala +++ /dev/null @@ -1,10 +0,0 @@ -package t8011 - -class ThingOps1(val x: String) extends AnyVal { - def fn[A]: Any = { - new X[A] { def foo(a: A) = a } - 0 - } -} - -trait X[B] { def foo(a: B): Any } diff --git a/tests/pos/valueclasses/t9298/JUse.java b/tests/pos/valueclasses/t9298/JUse.java deleted file mode 100644 index a872c895a..000000000 --- a/tests/pos/valueclasses/t9298/JUse.java +++ /dev/null @@ -1,7 +0,0 @@ -package t9298; - -class JUse { - public static Meter jm() { - return new Meter(2); - } -} diff --git a/tests/pos/valueclasses/t9298/Meter.scala b/tests/pos/valueclasses/t9298/Meter.scala deleted file mode 100644 index 290b28509..000000000 --- a/tests/pos/valueclasses/t9298/Meter.scala +++ /dev/null @@ -1,3 +0,0 @@ -package t9298 - -class Meter(val x: Int) extends AnyVal diff --git a/tests/pos/valueclasses/t9298/Use.scala b/tests/pos/valueclasses/t9298/Use.scala deleted file mode 100644 index 41f1fb035..000000000 --- a/tests/pos/valueclasses/t9298/Use.scala +++ /dev/null @@ -1,9 +0,0 @@ -// TODO: this should be a run test once we have run tests - -package t9298 - -object Use { - def main(args: Array[String]): Unit = { - val x: Meter = JUse.jm - } -} diff --git a/tests/pos/valueclasses/value-class-override-no-spec.flags b/tests/pos/valueclasses/value-class-override-no-spec.flags deleted file mode 100644 index a7e64e4f0..000000000 --- a/tests/pos/valueclasses/value-class-override-no-spec.flags +++ /dev/null @@ -1 +0,0 @@ --no-specialization \ No newline at end of file diff --git a/tests/pos/valueclasses/value-class-override-no-spec.scala b/tests/pos/valueclasses/value-class-override-no-spec.scala deleted file mode 100644 index 058e3e911..000000000 --- a/tests/pos/valueclasses/value-class-override-no-spec.scala +++ /dev/null @@ -1,11 +0,0 @@ -package value_class_override_no_spec - -// There are two versions of this tests: one with and one without specialization. -// The bug was only exposed *without* specialization. -trait T extends Any { - def x: Any -} - -final class StringOps(val repr0: String) extends AnyVal with T { - def x = () -} diff --git a/tests/pos/valueclasses/value-class-override-spec.scala b/tests/pos/valueclasses/value-class-override-spec.scala deleted file mode 100644 index c315be8d0..000000000 --- a/tests/pos/valueclasses/value-class-override-spec.scala +++ /dev/null @@ -1,11 +0,0 @@ -package value_class_override_spec - -// There are two versions of this tests: one with and one without specialization. -// The bug was only exposed *without* specialization. -trait T extends Any { - def x: Any -} - -final class StringOps(val repr0: String) extends AnyVal with T { - def x = () -} diff --git a/tests/pos/valueclasses/xlint1.flags b/tests/pos/valueclasses/xlint1.flags deleted file mode 100644 index 7949c2afa..000000000 --- a/tests/pos/valueclasses/xlint1.flags +++ /dev/null @@ -1 +0,0 @@ --Xlint -Xfatal-warnings diff --git a/tests/pos/valueclasses/xlint1.scala b/tests/pos/valueclasses/xlint1.scala deleted file mode 100644 index c2f39f9b3..000000000 --- a/tests/pos/valueclasses/xlint1.scala +++ /dev/null @@ -1,15 +0,0 @@ -package xlint1 - -package object foo { - implicit class Bar[T](val x: T) extends AnyVal { - def bippy = 1 - } -} - -package foo { - object Baz { - def main(args: Array[String]): Unit = { - "abc".bippy - } - } -} -- cgit v1.2.3 From 46b325373c8ec516be2b6b1c6024ae1c783fbc8f Mon Sep 17 00:00:00 2001 From: Martijn Hoekstra Date: Thu, 8 Sep 2016 12:25:13 +0200 Subject: test negtest path with / rather than path separator --- test/test/CompilerTest.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/test/CompilerTest.scala b/test/test/CompilerTest.scala index 6bd5f7030..dea6a30b1 100644 --- a/test/test/CompilerTest.scala +++ b/test/test/CompilerTest.scala @@ -228,7 +228,7 @@ abstract class CompilerTest { private def expectedErrors(filePath: String): List[ErrorsInFile] = expectedErrors(List(filePath)) - private def isNegTest(testPath: String) = testPath.contains(JFile.separator + "neg" + JFile.separator) + private def isNegTest(testPath: String) = testPath.contains("/neg/") private def compileArgs(args: Array[String], expectedErrorsPerFile: List[ErrorsInFile]) (implicit defaultOptions: List[String]): Unit = { -- cgit v1.2.3