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

Create message for missing arguments #16158

Merged
merged 3 commits into from Oct 10, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala
Expand Up @@ -67,7 +67,7 @@ enum ErrorMessageID(val isActive: Boolean = true) extends java.lang.Enum[ErrorMe
case AmbiguousOverloadID // errorNumber: 51
case ReassignmentToValID // errorNumber: 52
case TypeDoesNotTakeParametersID // errorNumber: 53
case ParameterizedTypeLacksArgumentsID // errorNumber: 54
case ParameterizedTypeLacksArgumentsID extends ErrorMessageID(isActive = false) // errorNumber: 54
case VarValParametersMayNotBeCallByNameID // errorNumber: 55
case MissingTypeParameterForID // errorNumber: 56
case DoesNotConformToBoundID // errorNumber: 57
Expand Down Expand Up @@ -184,7 +184,8 @@ enum ErrorMessageID(val isActive: Boolean = true) extends java.lang.Enum[ErrorMe
case ImplicitSearchTooLargeID // errorNumber: 168
case TargetNameOnTopLevelClassID // errorNumber: 169
case NotClassTypeID // errorNumber 170

case MissingArgumentID // errorNumer 171

def errorNumber = ordinal - 1

object ErrorMessageID:
Expand Down
17 changes: 8 additions & 9 deletions compiler/src/dotty/tools/dotc/reporting/messages.scala
Expand Up @@ -1406,15 +1406,6 @@ import cc.CaptureSet.IdentityCaptRefMap
|"""
}

class ParameterizedTypeLacksArguments(psym: Symbol)(using Context)
extends TypeMsg(ParameterizedTypeLacksArgumentsID) {
def msg = em"Parameterized $psym lacks argument list"
def explain =
em"""The $psym is declared with non-implicit parameters, you may not leave
|out the parameter list when extending it.
|"""
}

class VarValParametersMayNotBeCallByName(name: TermName, mutable: Boolean)(using Context)
extends SyntaxMsg(VarValParametersMayNotBeCallByNameID) {
def varOrVal = if (mutable) em"${hl("var")}" else em"${hl("val")}"
Expand Down Expand Up @@ -1445,6 +1436,13 @@ import cc.CaptureSet.IdentityCaptRefMap
def explain = em"A fully applied type is expected but $tpe takes $numParams $parameters"
}

class MissingArgument(pname: Name, methString: String)(using Context)
extends TypeMsg(MissingArgumentID):
def msg =
if pname.firstPart contains '$' then s"not enough arguments for $methString"
else s"missing argument for parameter $pname of $methString"
def explain = ""

class DoesNotConformToBound(tpe: Type, which: String, bound: Type)(using Context)
extends TypeMismatchMsg(
if which == "lower" then bound else tpe,
Expand Down Expand Up @@ -2535,3 +2533,4 @@ import cc.CaptureSet.IdentityCaptRefMap
extends TypeMsg(NotClassTypeID), ShowMatchTrace(tp):
def msg = ex"$tp is not a class type"
def explain = ""

8 changes: 2 additions & 6 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Expand Up @@ -561,12 +561,8 @@ trait Applications extends Compatibility {
else
formals1

def missingArg(n: Int): Unit = {
val pname = methodType.paramNames(n)
fail(
if (pname.firstPart contains '$') s"not enough arguments for $methString"
else s"missing argument for parameter $pname of $methString")
}
def missingArg(n: Int): Unit =
fail(MissingArgument(methodType.paramNames(n), methString))

def tryDefault(n: Int, args1: List[Arg]): Unit = {
val sym = methRef.symbol
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/dotty/tools/repl/ShadowingTests.scala
Expand Up @@ -80,7 +80,7 @@ class ShadowingTests extends ReplTest(options = ShadowingTests.options):
shadowed = "class C(val c: Int)",
script =
"""|scala> new C().c
|-- Error: ----------------------------------------------------------------------
|-- [E171] Type Error: ----------------------------------------------------------
|1 | new C().c
| | ^^^^^^^
| | missing argument for parameter c of constructor C in class C: (c: Int): C
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/i16130.check
@@ -0,0 +1,4 @@
-- [E171] Type Error: tests/neg/i16130.scala:3:16 ----------------------------------------------------------------------
3 | val foo = new Foo {} // error
| ^^^
| missing argument for parameter x of constructor Foo in trait Foo: (x: Int): Foo
3 changes: 3 additions & 0 deletions tests/neg/i16130.scala
@@ -0,0 +1,3 @@
@main def ParameterizedTypeLacksArgumentsID =
trait Foo(x: Int)
val foo = new Foo {} // error
2 changes: 1 addition & 1 deletion tests/neg/i6778.check
Expand Up @@ -4,7 +4,7 @@
| class A is not a trait
|
| longer explanation available when compiling with `-explain`
-- Error: tests/neg/i6778.scala:3:6 ------------------------------------------------------------------------------------
-- [E171] Type Error: tests/neg/i6778.scala:3:6 ------------------------------------------------------------------------
3 |class Bar extends Foo with A(10) // error // error
| ^
| missing argument for parameter x of constructor A in class A: (x: Int): A
2 changes: 1 addition & 1 deletion tests/neg/i9436.check
Expand Up @@ -4,7 +4,7 @@
| method f1 must be called with () argument
|
| longer explanation available when compiling with `-explain`
-- Error: tests/neg/i9436.scala:9:14 -----------------------------------------------------------------------------------
-- [E171] Type Error: tests/neg/i9436.scala:9:14 -----------------------------------------------------------------------
9 | println(x.f2(1)) // error
| ^^^^^^^
| missing argument for parameter y of method f2: (x: Int, y: Int): Int