Skip to content

Commit 20e54a3

Browse files
committed
Fix valueOf
ValueOf would happily return a value for non-value types, e.g. valueOf[String]. This would crash the backend later. This commit replaces the crash with a type error. Ideally, though, this should work as expected in inlined code.
1 parent 7c38fe8 commit 20e54a3

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ trait Implicits { self: Typer =>
773773
success(Literal(c))
774774
case TypeRef(_, sym) if sym == defn.UnitClass =>
775775
success(Literal(Constant(())))
776-
case n: NamedType =>
776+
case n: TermRef =>
777777
success(ref(n))
778778
case tp =>
779779
EmptyTree

tests/neg/i6241.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Test extends App {
2+
inline def v[T] = valueOf[T] // error
3+
4+
println(v[String])
5+
}

0 commit comments

Comments
 (0)