mirror of
https://github.com/dlang/dmd.git
synced 2025-04-25 20:50:41 +03:00
Don't raise "cannot return non-void" on Terror (#21028)
This commit is contained in:
parent
90e1a584b5
commit
53024b9fc5
6 changed files with 43 additions and 46 deletions
|
@ -2603,7 +2603,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
|
|||
|
||||
if (tbret && tbret.ty == Tvoid || convToVoid)
|
||||
{
|
||||
if (!convToVoid)
|
||||
if (!convToVoid && !texp.isTypeError())
|
||||
{
|
||||
error(rs.loc, "cannot return non-void from `void` function");
|
||||
errors = true;
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
/*
|
||||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/diag10405.d(10): Error: cannot return non-void from `void` function
|
||||
---
|
||||
*/
|
||||
|
||||
void main()
|
||||
{
|
||||
return 10;
|
||||
}
|
|
@ -13,12 +13,12 @@ fail_compilation/diag20888.d(49): Error: return value `callback` of type `int de
|
|||
fail_compilation/diag20888.d(54): Error: return value `() => 3755` of type `int function() pure nothrow @nogc @safe` does not match return type `int`, and cannot be implicitly converted
|
||||
fail_compilation/diag20888.d(54): Did you intend to call the function pointer?
|
||||
fail_compilation/diag20888.d(59): Error: `return` expression expected
|
||||
fail_compilation/diag20888.d(64): Error: cannot return non-void from `void` function
|
||||
fail_compilation/diag20888.d(70): Error: return value `() => i` of type `int delegate() pure nothrow @nogc @safe` does not match return type `int`, and cannot be implicitly converted
|
||||
fail_compilation/diag20888.d(70): Did you intend to call the delegate?
|
||||
---
|
||||
*/
|
||||
|
||||
|
||||
int alpha(int function() callback)
|
||||
{
|
||||
return callback;
|
||||
|
@ -59,10 +59,10 @@ int theta()
|
|||
return;
|
||||
}
|
||||
|
||||
void iota()
|
||||
{
|
||||
return 0xEAB;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int kappa()
|
||||
{
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
/*
|
||||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/fail305.d(10): Error: cannot return non-void from `void` function
|
||||
---
|
||||
*/
|
||||
|
||||
void main()
|
||||
{
|
||||
return "a";
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
/*
|
||||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/fail41.d(17): Error: cannot return non-void from `void` function
|
||||
---
|
||||
*/
|
||||
|
||||
class MyClass
|
||||
{
|
||||
}
|
||||
|
||||
MyClass[char[]] myarray;
|
||||
|
||||
void fn()
|
||||
{
|
||||
foreach (MyClass mc; myarray)
|
||||
return mc;
|
||||
}
|
37
compiler/test/fail_compilation/nonvoid_return.d
Normal file
37
compiler/test/fail_compilation/nonvoid_return.d
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/nonvoid_return.d(15): Error: cannot return non-void from `void` function
|
||||
fail_compilation/nonvoid_return.d(18): Error: cannot return non-void from `void` function
|
||||
fail_compilation/nonvoid_return.d(29): Error: cannot return non-void from `void` function
|
||||
fail_compilation/nonvoid_return.d(32): Error: undefined identifier `NONEXISTENT`
|
||||
---
|
||||
*/
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
|
||||
void fs() => "a";
|
||||
|
||||
class MyClass
|
||||
{
|
||||
}
|
||||
|
||||
MyClass[char[]] myarray;
|
||||
|
||||
void fn()
|
||||
{
|
||||
foreach (MyClass mc; myarray)
|
||||
return mc;
|
||||
}
|
||||
|
||||
auto err() { NONEXISTENT++; }
|
||||
|
||||
// Because `err` contains an error, it fails to infer void and gets an error return type
|
||||
// Don't print the 'cannot return non-void' error in this case
|
||||
|
||||
void fe() => err;
|
Loading…
Add table
Add a link
Reference in a new issue