Skip to content

Commit c2a8dae

Browse files
committed
Add missing contents to vitual files
1 parent b386fbd commit c2a8dae

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

compiler/src/dotty/tools/dotc/util/SourceFile.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class SourceFile(val file: AbstractFile, computeContent: => Array[Char]) extends
3939
lazy val content = computeContent
4040

4141
def this(file: AbstractFile, codec: Codec) = this(file, new String(file.toByteArray, codec.charSet).toCharArray)
42-
def this(name: String, content: String) = this(new VirtualFile(name), content.toCharArray)
42+
def this(name: String, content: String) = this(new VirtualFile(name, content.getBytes), scala.io.Codec.UTF8)
4343

4444
/** Tab increment; can be overridden */
4545
def tabInc: Int = 8

compiler/src/dotty/tools/io/VirtualFile.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ class VirtualFile(val name: String, override val path: String) extends AbstractF
2525
*/
2626
def this(name: String) = this(name, name)
2727

28+
/**
29+
* Initializes this instance with the specified name and an
30+
* identical path.
31+
*
32+
* @param name the name of the virtual file to be created
33+
* @param content the initial contents of the virtual file
34+
* @return the created virtual file
35+
*/
36+
def this(name: String, content: Array[Byte]) = {
37+
this(name)
38+
this.content = content
39+
}
40+
2841
override def hashCode: Int = path.hashCode
2942
override def equals(that: Any): Boolean = that match {
3043
case x: VirtualFile => x.path == path

compiler/test-resources/repl/notFound

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
scala> Foo
2+
1 | Foo
3+
| ^^^
4+
| Not found: Foo

0 commit comments

Comments
 (0)