Skip to content

Commit

Permalink
feat(errors): make verrors=context global and update test outputs
Browse files Browse the repository at this point in the history
Signed-off-by: royalpinto007 <[email protected]>
  • Loading branch information
royalpinto007 committed Dec 4, 2024
1 parent 56eb579 commit aa45160
Show file tree
Hide file tree
Showing 1,604 changed files with 18,578 additions and 7,708 deletions.
33 changes: 33 additions & 0 deletions changelog/dmd.verror_context.dd
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Make `verror=context` Usage Global and Update Related Test Files

The `verror=context` error handling mechanism has been made global, ensuring that error messages now consistently include context information across the entire codebase. Previously, error handling was localized, leading to some errors lacking context in the output.

Example:
```
void main()
{
int[int] a = [];
int[int] b = [2:3, 4];
a = [];
}
```

**Before Global `verror=context`:**
```
fail_compilation/aa_init.d(13,18): Error: invalid associative array initializer `[]`, use `null` instead
fail_compilation/aa_init.d(14,24): Error: missing key for value `4` in initializer
fail_compilation/aa_init.d(15,9): Error: cannot implicitly convert expression `[]` of type `void[]` to `int[int]`
```

**After Global `verror=context`:**
```
fail_compilation/aa_init.d(19,18): Error: invalid associative array initializer `[]`, use `null` instead
int[int] a = [];
^
fail_compilation/aa_init.d(20,24): Error: missing key for value `4` in initializer
int[int] b = [2:3, 4];
^
fail_compilation/aa_init.d(21,9): Error: cannot implicitly convert expression `[]` of type `void[]` to `int[int]`
a = [];
^
```
2 changes: 2 additions & 0 deletions compiler/src/dmd/globals.d
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ extern (C++) struct Global
params.v.color = detectTerminal();
}

params.v.printErrorContext = true; // Enable error context globally by default

compileEnv.versionNumber = parseVersionNumber(versionString());

/* Initialize date, time, and timestamp
Expand Down
4 changes: 4 additions & 0 deletions compiler/src/dmd/mars.d
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,10 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param
{
params.v.printErrorContext = true;
}
else if (startsWith(p + 9, "none"))
{
params.v.printErrorContext = false; // Disable error context
}
else if (!params.v.errorLimit.parseDigits(p.toDString()[9 .. $]))
{
errorInvalidSwitch(p, "Only number, `spec`, or `context` are allowed for `-verrors`");
Expand Down
80 changes: 60 additions & 20 deletions compiler/test/compilable/b16976.d
Original file line number Diff line number Diff line change
@@ -1,26 +1,66 @@
/* REQUIRED_ARGS: -m64
TEST_OUTPUT:
---
compilable/b16976.d(33): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
compilable/b16976.d(34): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
compilable/b16976.d(35): Deprecation: foreach: loop index implicitly converted from `size_t` to `char`
compilable/b16976.d(36): Deprecation: foreach: loop index implicitly converted from `size_t` to `char`
compilable/b16976.d(41): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
compilable/b16976.d(42): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
compilable/b16976.d(43): Deprecation: foreach: loop index implicitly converted from `size_t` to `char`
compilable/b16976.d(44): Deprecation: foreach: loop index implicitly converted from `size_t` to `char`
compilable/b16976.d(50): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
compilable/b16976.d(51): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
compilable/b16976.d(52): Deprecation: foreach: loop index implicitly converted from `size_t` to `char`
compilable/b16976.d(53): Deprecation: foreach: loop index implicitly converted from `size_t` to `char`
compilable/b16976.d(58): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
compilable/b16976.d(59): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
compilable/b16976.d(60): Deprecation: foreach: loop index implicitly converted from `size_t` to `char`
compilable/b16976.d(61): Deprecation: foreach: loop index implicitly converted from `size_t` to `char`
compilable/b16976.d(62): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
compilable/b16976.d(63): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
compilable/b16976.d(64): Deprecation: foreach: loop index implicitly converted from `size_t` to `char`
compilable/b16976.d(65): Deprecation: foreach: loop index implicitly converted from `size_t` to `char`
compilable/b16976.d(73): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
foreach(int i, v; dyn) { }
^
compilable/b16976.d(74): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
foreach_reverse(int i, v; dyn) { }
^
compilable/b16976.d(75): Deprecation: foreach: loop index implicitly converted from `size_t` to `char`
foreach(char i, v; dyn) { }
^
compilable/b16976.d(76): Deprecation: foreach: loop index implicitly converted from `size_t` to `char`
foreach_reverse(char i, v; dyn) { }
^
compilable/b16976.d(81): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
foreach(int i, v; str) { }
^
compilable/b16976.d(82): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
foreach_reverse(int i, v; str) { }
^
compilable/b16976.d(83): Deprecation: foreach: loop index implicitly converted from `size_t` to `char`
foreach(char i, v; str) { }
^
compilable/b16976.d(84): Deprecation: foreach: loop index implicitly converted from `size_t` to `char`
foreach_reverse(char i, v; str) { }
^
compilable/b16976.d(90): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
foreach(int i, dchar v; dyn) { }
^
compilable/b16976.d(91): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
foreach_reverse(int i, dchar v; dyn) { }
^
compilable/b16976.d(92): Deprecation: foreach: loop index implicitly converted from `size_t` to `char`
foreach(char i, dchar v; dyn) { }
^
compilable/b16976.d(93): Deprecation: foreach: loop index implicitly converted from `size_t` to `char`
foreach_reverse(char i, dchar v; dyn) { }
^
compilable/b16976.d(98): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
foreach(int i, dchar v; str) { }
^
compilable/b16976.d(99): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
foreach_reverse(int i, dchar v; str) { }
^
compilable/b16976.d(100): Deprecation: foreach: loop index implicitly converted from `size_t` to `char`
foreach(char i, dchar v; str) { }
^
compilable/b16976.d(101): Deprecation: foreach: loop index implicitly converted from `size_t` to `char`
foreach_reverse(char i, dchar v; str) { }
^
compilable/b16976.d(102): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
foreach(int i, dchar v; chr) { }
^
compilable/b16976.d(103): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
foreach_reverse(int i, dchar v; chr) { }
^
compilable/b16976.d(104): Deprecation: foreach: loop index implicitly converted from `size_t` to `char`
foreach(char i, dchar v; chr) { }
^
compilable/b16976.d(105): Deprecation: foreach: loop index implicitly converted from `size_t` to `char`
foreach_reverse(char i, dchar v; chr) { }
^
---
*/
void main()
Expand Down
4 changes: 3 additions & 1 deletion compiler/test/compilable/chkformat.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
/*
TEST_OUTPUT:
----
compilable/chkformat.d(14): Deprecation: more format specifiers than 0 arguments
compilable/chkformat.d(16): Deprecation: more format specifiers than 0 arguments
printf("%d \n");
^
----
*/
import core.stdc.stdio;
Expand Down
4 changes: 3 additions & 1 deletion compiler/test/compilable/compile1.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// EXTRA_FILES: imports/a12506.d
/* TEST_OUTPUT:
---
compilable/compile1.d(230): Deprecation: use of complex type `cdouble` is deprecated, use `std.complex.Complex!(double)` instead
compilable/compile1.d(232): Deprecation: use of complex type `cdouble` is deprecated, use `std.complex.Complex!(double)` instead
cdouble c6096;
^
---
*/

Expand Down
22 changes: 16 additions & 6 deletions compiler/test/compilable/ddoc10236.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@
/*
TEST_OUTPUT:
---
compilable/ddoc10236.d(35): Warning: Ddoc: parameter count mismatch, expected 2, got 1
compilable/ddoc10236.d(47): Warning: Ddoc: function declaration has no parameter 'y'
compilable/ddoc10236.d(59): Warning: Ddoc: function declaration has no parameter 'y'
compilable/ddoc10236.d(59): Warning: Ddoc: parameter count mismatch, expected 1, got 2
compilable/ddoc10236.d(71): Warning: Ddoc: parameter count mismatch, expected 2, got 0
compilable/ddoc10236.d(71): Note that the format is `param = description`
compilable/ddoc10236.d(45): Warning: Ddoc: parameter count mismatch, expected 2, got 1
void foo_count_mismatch(int x, int y) // Warning: Ddoc: parameter count mismatch
^
compilable/ddoc10236.d(57): Warning: Ddoc: function declaration has no parameter 'y'
void foo_no_param_y(int x, int z) // Warning: Ddoc: function declaration has no parameter 'y'
^
compilable/ddoc10236.d(69): Warning: Ddoc: function declaration has no parameter 'y'
void foo_count_mismatch_no_param_y(int x)
^
compilable/ddoc10236.d(69): Warning: Ddoc: parameter count mismatch, expected 1, got 2
void foo_count_mismatch_no_param_y(int x)
^
compilable/ddoc10236.d(81): Warning: Ddoc: parameter count mismatch, expected 2, got 0
void foo_count_mismatch_wrong_format(int x, int y)
^
compilable/ddoc10236.d(81): Note that the format is `param = description`
---
*/

Expand Down
18 changes: 13 additions & 5 deletions compiler/test/compilable/ddoc10236b.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@
/*
TEST_OUTPUT:
---
compilable/ddoc10236b.d(44): Warning: Ddoc: parameter count mismatch, expected 1, got 0
compilable/ddoc10236b.d(44): Note that the format is `param = description`
compilable/ddoc10236b.d(56): Warning: Ddoc: function declaration has no parameter 'y'
compilable/ddoc10236b.d(68): Warning: Ddoc: function declaration has no parameter 'y'
compilable/ddoc10236b.d(68): Warning: Ddoc: parameter count mismatch, expected 0, got 1
compilable/ddoc10236b.d(52): Warning: Ddoc: parameter count mismatch, expected 1, got 0
void foo_count_mismatch(int x)(int y) // Warning: Ddoc: parameter count mismatch
^
compilable/ddoc10236b.d(52): Note that the format is `param = description`
compilable/ddoc10236b.d(64): Warning: Ddoc: function declaration has no parameter 'y'
void foo_no_param_y(int x)(int z) // Warning: Ddoc: function declaration has no parameter 'y'
^
compilable/ddoc10236b.d(76): Warning: Ddoc: function declaration has no parameter 'y'
void foo_count_mismatch_no_param_y(int x)()
^
compilable/ddoc10236b.d(76): Warning: Ddoc: parameter count mismatch, expected 0, got 1
void foo_count_mismatch_no_param_y(int x)()
^
---
*/

Expand Down
16 changes: 12 additions & 4 deletions compiler/test/compilable/ddoc13502.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@
/*
TEST_OUTPUT:
---
compilable/ddoc13502.d(14): Warning: Ddoc: Stray '('. This may cause incorrect Ddoc output. Use $(LPAREN) instead for unpaired left parentheses.
compilable/ddoc13502.d(17): Warning: Ddoc: Stray '('. This may cause incorrect Ddoc output. Use $(LPAREN) instead for unpaired left parentheses.
compilable/ddoc13502.d(21): Warning: Ddoc: Stray '('. This may cause incorrect Ddoc output. Use $(LPAREN) instead for unpaired left parentheses.
compilable/ddoc13502.d(24): Warning: Ddoc: Stray '('. This may cause incorrect Ddoc output. Use $(LPAREN) instead for unpaired left parentheses.
compilable/ddoc13502.d(22): Warning: Ddoc: Stray '('. This may cause incorrect Ddoc output. Use $(LPAREN) instead for unpaired left parentheses.
enum isSomeString(T) = true;
^
compilable/ddoc13502.d(25): Warning: Ddoc: Stray '('. This may cause incorrect Ddoc output. Use $(LPAREN) instead for unpaired left parentheses.
enum bool isArray(T) = true;
^
compilable/ddoc13502.d(29): Warning: Ddoc: Stray '('. This may cause incorrect Ddoc output. Use $(LPAREN) instead for unpaired left parentheses.
extern(C) alias int T1;
^
compilable/ddoc13502.d(32): Warning: Ddoc: Stray '('. This may cause incorrect Ddoc output. Use $(LPAREN) instead for unpaired left parentheses.
extern(C) alias T2 = int;
^
---
*/

Expand Down
19 changes: 11 additions & 8 deletions compiler/test/compilable/ddoc4899.d
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
// PERMUTE_ARGS:
// REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -wi -o-

/*
/+
TEST_OUTPUT:
---
compilable/ddoc4899.d(18): Warning: Ddoc: Stray '('. This may cause incorrect Ddoc output. Use $(LPAREN) instead for unpaired left parentheses.
compilable/ddoc4899.d(19): Warning: Ddoc: Stray ')'. This may cause incorrect Ddoc output. Use $(RPAREN) instead for unpaired right parentheses.
compilable/ddoc4899.d(21): Warning: Ddoc: Stray '('. This may cause incorrect Ddoc output. Use $(LPAREN) instead for unpaired left parentheses.
/** ( */ int a;
^
compilable/ddoc4899.d(22): Warning: Ddoc: Stray ')'. This may cause incorrect Ddoc output. Use $(RPAREN) instead for unpaired right parentheses.
/** ) */ int b;
^
---
*/

/++
(See accompanying file LICENSE_1_0.txt or copy at
foo:)
+/

// (See accompanying file LICENSE_1_0.txt or copy at
// foo:)

module d;

/** ( */ int a;
Expand Down
52 changes: 39 additions & 13 deletions compiler/test/compilable/depmsg.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,45 @@
REQUIRED_ARGS: -dw
TEST_OUTPUT:
---
compilable/depmsg.d(39): Deprecation: struct `depmsg.main.Inner.A` is deprecated - With message!
compilable/depmsg.d(39): Deprecation: struct `depmsg.main.Inner.A` is deprecated - With message!
compilable/depmsg.d(40): Deprecation: class `depmsg.main.Inner.B` is deprecated - With message!
compilable/depmsg.d(40): Deprecation: class `depmsg.main.Inner.B` is deprecated - With message!
compilable/depmsg.d(41): Deprecation: interface `depmsg.main.Inner.C` is deprecated - With message!
compilable/depmsg.d(41): Deprecation: interface `depmsg.main.Inner.C` is deprecated - With message!
compilable/depmsg.d(42): Deprecation: union `depmsg.main.Inner.D` is deprecated - With message!
compilable/depmsg.d(42): Deprecation: union `depmsg.main.Inner.D` is deprecated - With message!
compilable/depmsg.d(43): Deprecation: enum `depmsg.main.Inner.E` is deprecated - With message!
compilable/depmsg.d(43): Deprecation: enum `depmsg.main.Inner.E` is deprecated - With message!
compilable/depmsg.d(45): Deprecation: alias `depmsg.main.Inner.G` is deprecated - With message!
compilable/depmsg.d(46): Deprecation: variable `depmsg.main.Inner.H` is deprecated - With message!
compilable/depmsg.d(47): Deprecation: class `depmsg.main.Inner.I()` is deprecated - With message!
compilable/depmsg.d(65): Deprecation: struct `depmsg.main.Inner.A` is deprecated - With message!
A a;
^
compilable/depmsg.d(65): Deprecation: struct `depmsg.main.Inner.A` is deprecated - With message!
A a;
^
compilable/depmsg.d(66): Deprecation: class `depmsg.main.Inner.B` is deprecated - With message!
B b;
^
compilable/depmsg.d(66): Deprecation: class `depmsg.main.Inner.B` is deprecated - With message!
B b;
^
compilable/depmsg.d(67): Deprecation: interface `depmsg.main.Inner.C` is deprecated - With message!
C c;
^
compilable/depmsg.d(67): Deprecation: interface `depmsg.main.Inner.C` is deprecated - With message!
C c;
^
compilable/depmsg.d(68): Deprecation: union `depmsg.main.Inner.D` is deprecated - With message!
D d;
^
compilable/depmsg.d(68): Deprecation: union `depmsg.main.Inner.D` is deprecated - With message!
D d;
^
compilable/depmsg.d(69): Deprecation: enum `depmsg.main.Inner.E` is deprecated - With message!
E e;
^
compilable/depmsg.d(69): Deprecation: enum `depmsg.main.Inner.E` is deprecated - With message!
E e;
^
compilable/depmsg.d(71): Deprecation: alias `depmsg.main.Inner.G` is deprecated - With message!
G g;
^
compilable/depmsg.d(72): Deprecation: variable `depmsg.main.Inner.H` is deprecated - With message!
auto h = H;
^
compilable/depmsg.d(73): Deprecation: class `depmsg.main.Inner.I()` is deprecated - With message!
I!() i;
^
---
*/
void main()
Expand Down
24 changes: 13 additions & 11 deletions compiler/test/compilable/deprecated_override.d
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,18 @@ Only the parent declaration is deprecated
TEST_OUTPUT:
----
compilable/deprecated_override.d(44): Deprecation: `deprecated_override.IntroducingChild.foo` is overriding the deprecated method `deprecated_override.IntroducingParent.foo`
compilable/deprecated_override.d(48): Deprecation: `deprecated_override.IntroducingChild.bar` is overriding the deprecated method `deprecated_override.IntroducingParent.bar`
compilable/deprecated_override.d(54): Deprecation: `deprecated_override.IntroducingChild.foo` is overriding the deprecated method `deprecated_override.IntroducingParent.foo`
override void foo() {}
^
compilable/deprecated_override.d(58): Deprecation: `deprecated_override.IntroducingChild.bar` is overriding the deprecated method `deprecated_override.IntroducingParent.bar`
override void bar() {}
^
compilable/deprecated_override.d(85): Deprecation: `deprecated_override.OverrideChild.foo` cannot be marked as `deprecated` because it is overriding a function in the base class
deprecated override void foo() {}
^
compilable/deprecated_override.d(89): Deprecation: `deprecated_override.OverrideChild.bar` cannot be marked as `deprecated` because it is overriding a function in the base class
deprecated override void bar() {}
^
----
**/

Expand Down Expand Up @@ -59,15 +69,7 @@ class IntroducingGrandchild : IntroducingChild
override void bar() {}
}

/**
Only the overriding declaration is deprecated
TEST_OUTPUT:
----
compilable/deprecated_override.d(83): Deprecation: `deprecated_override.OverrideChild.foo` cannot be marked as `deprecated` because it is overriding a function in the base class
compilable/deprecated_override.d(87): Deprecation: `deprecated_override.OverrideChild.bar` cannot be marked as `deprecated` because it is overriding a function in the base class
----
**/
// Only the overriding declaration is deprecated

class OverrideParent
{
Expand Down
12 changes: 9 additions & 3 deletions compiler/test/compilable/deprecationlimit.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
REQUIRED_ARGS: -verrors=3
TEST_OUTPUT:
---
compilable/deprecationlimit.d(18): Deprecation: function `deprecationlimit.f` is deprecated
compilable/deprecationlimit.d(19): Deprecation: function `deprecationlimit.f` is deprecated
compilable/deprecationlimit.d(20): Deprecation: function `deprecationlimit.f` is deprecated
compilable/deprecationlimit.d(24): Deprecation: function `deprecationlimit.f` is deprecated
f();
^
compilable/deprecationlimit.d(25): Deprecation: function `deprecationlimit.f` is deprecated
f();
^
compilable/deprecationlimit.d(26): Deprecation: function `deprecationlimit.f` is deprecated
f();
^
1 deprecation warning omitted, use `-verrors=0` to show all
---
*/
Expand Down
Loading

0 comments on commit aa45160

Please sign in to comment.