Dotty: Strange program with incorrect type ascription compiles

Created on 28 Dec 2020  路  3Comments  路  Source: lampepfl/dotty

Minimized code

object T:
  class A
  val a = new A : Int
end T

@main def m =
  println(T.a)

This is with options:

scalacOptions ++= Seq(
  "-deprecation",
  "-encoding", "UTF-8",
  "-feature",
  "-unchecked",
  "-Yindent-colons",
  "-Ykind-projector",
  "-language:strict",
  "-source:3.1",
)

https://scastie.scala-lang.org/R2s6G90oTQ2ZcE6dn4ZlPg

Output

T$A@5b61791c

Expectation

Should not compile.

bug

Most helpful comment

this only passes for me when using -Yindent-colons, the parser drops the type ascription

All 3 comments

Would be good to get a solution as well! I am getting a bit tired of code obfuscation contests.

TBH this came up completely by accident (I was not trying to expose a problem), in my real-world code base, and I have no idea what's going on. Seems like this is a parser bug.

this only passes for me when using -Yindent-colons, the parser drops the type ascription

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ohze picture ohze  路  3Comments

liufengyun picture liufengyun  路  3Comments

andreaTP picture andreaTP  路  3Comments

mcku picture mcku  路  3Comments

milessabin picture milessabin  路  3Comments