From 6068e8188c3fb9b984e30d5536fac779dce07d3b Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Sun, 4 Dec 2022 19:21:48 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20Issue=C2=A09848=20-=20Better=20diagnostic?= =?UTF-8?q?=20when=20type=20was=20not=20expected?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- compiler/src/dmd/parse.d | 9 ++++++++- compiler/test/fail_compilation/fail54.d | 10 +++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/compiler/src/dmd/parse.d b/compiler/src/dmd/parse.d index a83ce9eaab4b..bc03490ee128 100644 --- a/compiler/src/dmd/parse.d +++ b/compiler/src/dmd/parse.d @@ -8257,6 +8257,13 @@ LagainStc: t = AST.Type.tdchar; goto LabelX; LabelX: + const next = peekNext(); + if (next != TOK.leftParenthesis && next != TOK.dot) + { + // defer error for better diagnostics + e = new AST.TypeExp(loc, parseType); + break; + } nextToken(); if (token.value == TOK.leftParenthesis) { @@ -8264,7 +8271,7 @@ LagainStc: e = new AST.CallExp(loc, e, parseArguments()); break; } - check(TOK.dot, t.toChars()); + check(TOK.dot); if (token.value != TOK.identifier) { error("found `%s` when expecting identifier following `%s`.", token.toChars(), t.toChars()); diff --git a/compiler/test/fail_compilation/fail54.d b/compiler/test/fail_compilation/fail54.d index e52c5336be6d..e232523ed651 100644 --- a/compiler/test/fail_compilation/fail54.d +++ b/compiler/test/fail_compilation/fail54.d @@ -1,7 +1,12 @@ /* TEST_OUTPUT: --- -fail_compilation/fail54.d(22): Error: incompatible types for `(0) == (Exception)`: cannot use `==` with types +fail_compilation/fail54.d(27): Error: incompatible types for `(0) == (Exception)`: cannot use `==` with types +fail_compilation/fail54.d(28): Error: incompatible types for `("") == (int)`: cannot use `==` with types +fail_compilation/fail54.d(29): Error: incompatible types for `(true) == (int)`: cannot use `==` with types +fail_compilation/fail54.d(29): while evaluating: `static assert(true == (int))` +fail_compilation/fail54.d(30): Error: incompatible types for `(true) == (int[string])`: cannot use `==` with types +fail_compilation/fail54.d(30): while evaluating: `static assert(true == (int[string]))` --- */ @@ -20,4 +25,7 @@ module dstress.nocompile.bug_mtype_507_C; void test() { 0 == Exception; + "" == int; + static assert(is(int) == int); + static assert(is(int[string]) == int[string]); }