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

Update phrasing for NotClassType explain error message #19635

Merged
merged 2 commits into from
Feb 19, 2024
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
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/reporting/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2775,7 +2775,11 @@ extends SyntaxMsg(TargetNameOnTopLevelClassID):
class NotClassType(tp: Type)(using Context)
extends TypeMsg(NotClassTypeID), ShowMatchTrace(tp):
def msg(using Context) = i"$tp is not a class type"
def explain(using Context) = ""
def explain(using Context) =
i"""A class type includes classes and traits in a specific order. Defining a class, even an anonymous class,
|requires specifying a linearization order for the traits it extends. For example, `A & B` is not a class type
|because it doesn't specify which trait takes precedence, A or B. For more information about class types, please see the Scala Language Specification.
|Class types also can't have refinements."""
aherlihy marked this conversation as resolved.
Show resolved Hide resolved

class NotConstant(suffix: String, tp: Type)(using Context)
extends TypeMsg(NotConstantID), ShowMatchTrace(tp):
Expand Down
5 changes: 5 additions & 0 deletions docs/_docs/contributing/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ checkfiles with the test outputs.
$ sbt
> testCompilation --update-checkfiles
```
Or for ScalaJS
```bash
$ sbt
> sjsCompilerTests/testOnly -- -Ddotty.tests.updateCheckfiles=TRUE
```

Use `--help` to see all the options
```bash
Expand Down
16 changes: 16 additions & 0 deletions tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.check
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@
14 | val b = js.constructorOf[NativeJSObject.type] // error
| ^^^^^^^^^^^^^^^^^^^
| NativeJSObject.type is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:16:27 -----------------------------
16 | val c = js.constructorOf[NativeJSClass with NativeJSTrait] // error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| NativeJSClass & NativeJSTrait is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:17:27 -----------------------------
17 | val d = js.constructorOf[NativeJSClass { def bar: Int }] // error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| NativeJSClass{def bar: Int} is not a class type
|
| longer explanation available when compiling with `-explain`
-- Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:19:27 -----------------------------------------
19 | val e = js.constructorOf[JSTrait] // error
| ^^^^^^^
Expand All @@ -36,19 +42,29 @@
20 | val f = js.constructorOf[JSObject.type] // error
| ^^^^^^^^^^^^^
| JSObject.type is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:22:27 -----------------------------
22 | val g = js.constructorOf[JSClass with JSTrait] // error
| ^^^^^^^^^^^^^^^^^^^^
| JSClass & JSTrait is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:23:27 -----------------------------
23 | val h = js.constructorOf[JSClass { def bar: Int }] // error
| ^^^^^^^^^^^^^^^^^^^^^^^^
| JSClass{def bar: Int} is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:25:42 -----------------------------
25 | def foo[A <: js.Any] = js.constructorOf[A] // error
| ^
| A is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:26:66 -----------------------------
26 | def bar[A <: js.Any: scala.reflect.ClassTag] = js.constructorOf[A] // error
| ^
| A is not a class type
|
| longer explanation available when compiling with `-explain`
16 changes: 16 additions & 0 deletions tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.check
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@
14 | val b = js.constructorTag[NativeJSObject.type] // error
| ^
| NativeJSObject.type is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:16:61 ----------------------------
16 | val c = js.constructorTag[NativeJSClass with NativeJSTrait] // error
| ^
| NativeJSClass & NativeJSTrait is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:17:59 ----------------------------
17 | val d = js.constructorTag[NativeJSClass { def bar: Int }] // error
| ^
| NativeJSClass{def bar: Int} is not a class type
|
| longer explanation available when compiling with `-explain`
-- Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:19:36 ----------------------------------------
19 | val e = js.constructorTag[JSTrait] // error
| ^
Expand All @@ -36,19 +42,29 @@
20 | val f = js.constructorTag[JSObject.type] // error
| ^
| JSObject.type is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:22:49 ----------------------------
22 | val g = js.constructorTag[JSClass with JSTrait] // error
| ^
| JSClass & JSTrait is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:23:53 ----------------------------
23 | val h = js.constructorTag[JSClass { def bar: Int }] // error
| ^
| JSClass{def bar: Int} is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:25:45 ----------------------------
25 | def foo[A <: js.Any] = js.constructorTag[A] // error
| ^
| A is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:26:69 ----------------------------
26 | def bar[A <: js.Any: scala.reflect.ClassTag] = js.constructorTag[A] // error
| ^
| A is not a class type
|
| longer explanation available when compiling with `-explain`
6 changes: 6 additions & 0 deletions tests/neg/classOf.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
6 | def f1[T] = classOf[T] // error
| ^
| T is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg/classOf.scala:7:32 ---------------------------------------------------------------------
7 | def f2[T <: String] = classOf[T] // error
| ^
| T is not a class type
|
| where: T is a type in method f2 with bounds <: String
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg/classOf.scala:9:18 ---------------------------------------------------------------------
9 | val y = classOf[C { type I = String }] // error
| ^^^^^^^^^^^^^^^^^^^^^
| Test.C{type I = String} is not a class type
|
| longer explanation available when compiling with `-explain`
4 changes: 4 additions & 0 deletions tests/neg/i13808.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
13 |case class Boom[A](value: A) derives OpaqueType, Foo // error // error
| ^^^^^^^^^^
| OpaqueTypes.OpaqueType is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg/i13808.scala:13:49 ---------------------------------------------------------------------
13 |case class Boom[A](value: A) derives OpaqueType, Foo // error // error
| ^^^
| FooModule.Foo is not a class type
|
| longer explanation available when compiling with `-explain`
Loading