Skip to content
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

Tweak AvoidMap's derivedSelect #16563

Merged
merged 1 commit into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ object TypeOps:
override def derivedSelect(tp: NamedType, pre: Type) =
if (pre eq tp.prefix)
tp
else tryWiden(tp, tp.prefix).orElse {
else (if pre.isSingleton then NoType else tryWiden(tp, tp.prefix)).orElse {
if (tp.isTerm && variance > 0 && !pre.isSingleton)
apply(tp.info.widenExpr)
else if (upper(pre).member(tp.name).exists)
Expand Down
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/io/AbstractFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,10 @@ abstract class AbstractFile extends Iterable[AbstractFile] {

// a race condition in creating the entry after the failed lookup may throw
val path = jpath.resolve(name)
if (isDir) Files.createDirectory(path)
else Files.createFile(path)
try
if (isDir) Files.createDirectory(path)
else Files.createFile(path)
catch case _: FileAlreadyExistsException => ()
new PlainFile(new File(path))
case lookup => lookup
}
Expand Down
13 changes: 13 additions & 0 deletions tests/pos/i16435.TreeUnpickler.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Derived from the CI failure in compiling TreeUnpickler.scala
class Foo
class Bar extends Foo:
type Self >: this.type <: Bar
final def meth(): Self = this

class Test:
def test(cond: Boolean, bar: Bar): Foo =
val res = bar
if cond then
res.meth()
else
res
8 changes: 8 additions & 0 deletions tests/pos/i16435.avoid.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Foo:
type Value
def test: Option[Value] =
val scr = {
val self: Foo.this.type = this
None: Option[self.Value]
}
scr
11 changes: 11 additions & 0 deletions tests/pos/i16435.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// scalac: -Werror
trait Base:
type Value
inline def oov: Option[Option[Value]] = None
def get: Option[Value]

trait X extends Base:
override def get: Option[Value] =
oov match // was: match may not be exhaustive
case Some(ov) => ov
case None => None