-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix REPL clashing with CWD artefacts #14021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package dotty.tools | ||
package repl | ||
|
||
import java.io.File | ||
import java.nio.file.Files | ||
|
||
import org.junit.{ After, AfterClass, BeforeClass, Ignore, Test } | ||
import org.junit.Assert._ | ||
import io.{ Directory, PlainDirectory } | ||
import dotc.core.Contexts._ | ||
import dotc.reporting.{ ErrorMessagesTest, StoreReporter } | ||
import vulpix.TestConfiguration | ||
|
||
object ShadowingBatchTests: | ||
val dir = Directory(Files.createTempDirectory("batch-shadow")) | ||
|
||
@BeforeClass def suiteStarting: Unit = dir.createDirectory() | ||
@AfterClass def suiteFinished: Unit = dir.deleteRecursively() | ||
|
||
class ShadowingBatchTests extends ErrorMessagesTest: | ||
import ShadowingBatchTests._ | ||
|
||
@After def testFinished: Unit = dir.list.foreach(_.deleteRecursively()) | ||
|
||
val compiler = new dotc.Compiler() | ||
|
||
override def initializeCtx(ictx: FreshContext) = inContext(ictx) { | ||
super.initializeCtx(ictx) | ||
val settings = ictx.settings; import settings._ | ||
ictx.setSetting(outputDir, new PlainDirectory(dir)) | ||
ictx.setSetting(classpath, classpath.value + File.pathSeparator + dir.jpath.toAbsolutePath) | ||
} | ||
|
||
@Test def file = | ||
checkMessages("class C(val c: Int)").expectNoErrors | ||
checkMessages("object rsline1 {\n def line1 = new C().c\n}").expect { (_, msgs) => | ||
assertMessageCount(1, msgs) | ||
assertEquals("missing argument for parameter c of constructor C in class C: (c: Int): C", msgs.head.message) | ||
} | ||
checkMessages("object rsline2 {\n def line2 = new C(13).c\n}").expectNoErrors | ||
checkMessages("object rsline3 {\n class C { val c = 42 }\n}").expectNoErrors | ||
checkMessages("import rsline3._\nobject rsline4 {\n def line4 = new C().c\n}").expectNoErrors | ||
|
||
@Test def directory = | ||
checkMessages("package foo\nclass C").expectNoErrors | ||
checkMessages("object rsline1 {\n def line1 = foo\n}").expect { (_, msgs) => | ||
assertMessageCount(1, msgs) | ||
assertEquals("package foo is not a value", msgs.head.message) | ||
} | ||
checkMessages("object rsline2 {\n val foo = 2\n}").expectNoErrors | ||
checkMessages("import rsline2._\nobject rsline3 {\n def line3 = foo\n}").expectNoErrors | ||
|
||
@Test def directoryJava = | ||
checkMessages("object rsline1 {\n def line1 = java\n}").expect { (_, msgs) => | ||
assertMessageCount(1, msgs) | ||
assertEquals("package java is not a value", msgs.head.message) | ||
} | ||
checkMessages("object rsline2 {\n val java = 2\n}").expectNoErrors | ||
checkMessages("import rsline2._\nobject rsline3 {\n def line3 = java\n}").expectNoErrors | ||
|
||
def checkMessages(source: String): Report = | ||
ctx = newContext | ||
val run = compiler.newRun(using ctx.fresh) | ||
run.compileFromStrings(List(source)) | ||
val runCtx = run.runContext | ||
if runCtx.reporter.hasErrors then | ||
val rep = runCtx.reporter.asInstanceOf[StoreReporter] | ||
val msgs = rep.removeBufferedMessages(using runCtx).map(_.msg).reverse | ||
new Report(msgs, runCtx) | ||
else new EmptyReport | ||
end ShadowingBatchTests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.