Skip to content

Commit

Permalink
Add supplemental error
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel committed Jan 28, 2025
1 parent c94c2a2 commit c36a8e2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
4 changes: 4 additions & 0 deletions compiler/src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -14775,6 +14775,8 @@ private bool checkArithmetic(Expression e, EXP op)
// Deprecated in 2.111
// In 2.121, remove this branch to let `checkValue` raise the error
deprecation(e.loc, "type `%s` has no value", e.toChars);
if (!e.type.isOpaqueType)
deprecationSupplemental(e.loc, "perhaps use `%s`.init", e.toChars);
return false;
}

Expand Down Expand Up @@ -14847,6 +14849,8 @@ bool checkValue(Expression e)
if (auto te = e.isTypeExp())
{
error(e.loc, "type `%s` has no value", e.toChars());
if (!e.type.isOpaqueType)
errorSupplemental(e.loc, "perhaps use `%s`.init", e.toChars());
return true;
}

Expand Down
12 changes: 12 additions & 0 deletions compiler/src/dmd/typesem.d
Original file line number Diff line number Diff line change
Expand Up @@ -7609,6 +7609,18 @@ bool checkRetType(TypeFunction tf, const ref Loc loc)
return false;
}

/// Returns: whether `t` is a struct/class/enum without a body
bool isOpaqueType(Type t)
{
if (auto te = t.isTypeEnum())
return te.sym.members is null;
if (auto ts = t.isTypeStruct())
return ts.sym.members is null;
if (auto tc = t.isTypeClass())
return tc.sym.members is null;
return false;
}


/******************************* Private *****************************************/

Expand Down
7 changes: 4 additions & 3 deletions compiler/test/fail_compilation/b17285.d
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/*
TEST_OUTPUT:
---
fail_compilation/b17285.d(14): Error: type `ONE` has no value
fail_compilation/b17285.d(14): Error: type `TWO` has no value
fail_compilation/b17285.d(14): Error: cannot implicitly convert expression `ONE` of type `b17285.ONE` to `int`
fail_compilation/b17285.d(15): Error: type `ONE` has no value
fail_compilation/b17285.d(15): perhaps use `ONE`.init
fail_compilation/b17285.d(15): Error: type `TWO` has no value
fail_compilation/b17285.d(15): Error: cannot implicitly convert expression `ONE` of type `b17285.ONE` to `int`
---
*/

Expand Down
3 changes: 2 additions & 1 deletion compiler/test/fail_compilation/ice9545.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
/*
TEST_OUTPUT:
----
fail_compilation/ice9545.d(13): Error: type `int` has no value
fail_compilation/ice9545.d(14): Error: type `int` has no value
fail_compilation/ice9545.d(14): perhaps use `int`.init
----
*/

Expand Down
20 changes: 12 additions & 8 deletions compiler/test/fail_compilation/test20763.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ REQUIRED_ARGS: -de
TEST_OUTPUT:
---
fail_compilation/test20763.d(21): Deprecation: type `ulong` has no value
fail_compilation/test20763.d(21): perhaps use `ulong.init` instead
fail_compilation/test20763.d(22): Deprecation: type `ulong` has no value
fail_compilation/test20763.d(22): perhaps use `ulong.init` instead
fail_compilation/test20763.d(23): Error: type `ulong` has no value
fail_compilation/test20763.d(24): Error: type `ulong` has no value
fail_compilation/test20763.d(25): Error: type `ulong` has no value
fail_compilation/test20763.d(26): Error: type `ulong` has no value
fail_compilation/test20763.d(25): Deprecation: type `ulong` has no value
fail_compilation/test20763.d(25): perhaps use `ulong`.init
fail_compilation/test20763.d(26): Deprecation: type `ulong` has no value
fail_compilation/test20763.d(26): perhaps use `ulong`.init
fail_compilation/test20763.d(27): Error: type `ulong` has no value
fail_compilation/test20763.d(27): perhaps use `ulong`.init
fail_compilation/test20763.d(28): Error: type `ulong` has no value
fail_compilation/test20763.d(28): perhaps use `ulong`.init
fail_compilation/test20763.d(29): Error: type `ulong` has no value
fail_compilation/test20763.d(29): perhaps use `ulong`.init
fail_compilation/test20763.d(30): Error: type `ulong` has no value
fail_compilation/test20763.d(30): perhaps use `ulong`.init
---
*/

Expand Down

0 comments on commit c36a8e2

Please sign in to comment.