use isXXX() functions for ReturnStatement semantic

This commit is contained in:
Walter Bright 2023-12-08 23:11:24 -08:00 committed by The Dlang Bot
parent 2625a1607c
commit 3ff8eb67a7

View file

@ -2526,10 +2526,9 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
if (fd.fes) if (fd.fes)
fd = fd.fes.func; // fd is now function enclosing foreach fd = fd.fes.func; // fd is now function enclosing foreach
TypeFunction tf = cast(TypeFunction)fd.type; auto tf = fd.type.isTypeFunction();
assert(tf.ty == Tfunction);
if (rs.exp && rs.exp.op == EXP.variable && (cast(VarExp)rs.exp).var == fd.vresult) if (rs.exp && rs.exp.isVarExp() && rs.exp.isVarExp().var == fd.vresult)
{ {
// return vresult; // return vresult;
if (sc.fes) if (sc.fes)
@ -2617,7 +2616,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
rs.exp.checkSharedAccess(sc, returnSharedRef); rs.exp.checkSharedAccess(sc, returnSharedRef);
// for static alias this: https://issues.dlang.org/show_bug.cgi?id=17684 // for static alias this: https://issues.dlang.org/show_bug.cgi?id=17684
if (rs.exp.op == EXP.type) if (rs.exp.isTypeExp())
rs.exp = resolveAliasThis(sc, rs.exp); rs.exp = resolveAliasThis(sc, rs.exp);
rs.exp = resolveProperties(sc, rs.exp); rs.exp = resolveProperties(sc, rs.exp);
@ -2633,14 +2632,14 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
// Extract side-effect part // Extract side-effect part
rs.exp = Expression.extractLast(rs.exp, e0); rs.exp = Expression.extractLast(rs.exp, e0);
if (rs.exp.op == EXP.call) if (rs.exp.isCallExp())
rs.exp = valueNoDtor(rs.exp); rs.exp = valueNoDtor(rs.exp);
/* Void-return function can have void / noreturn typed expression /* Void-return function can have void / noreturn typed expression
* on return statement. * on return statement.
*/ */
auto texp = rs.exp.type; auto texp = rs.exp.type;
const convToVoid = texp.ty == Tvoid || texp.ty == Tnoreturn; const convToVoid = texp.ty == Tvoid || texp.isTypeNoreturn();
if (tbret && tbret.ty == Tvoid || convToVoid) if (tbret && tbret.ty == Tvoid || convToVoid)
{ {
@ -2689,7 +2688,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
{ {
tf.next = rs.exp.type; tf.next = rs.exp.type;
} }
else if (tret.ty != Terror && !rs.exp.type.equals(tret)) else if (!tret.isTypeError() && !rs.exp.type.equals(tret))
{ {
int m1 = rs.exp.type.implicitConvTo(tret); int m1 = rs.exp.type.implicitConvTo(tret);
int m2 = tret.implicitConvTo(rs.exp.type); int m2 = tret.implicitConvTo(rs.exp.type);
@ -2790,7 +2789,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
// Found an actual return value before // Found an actual return value before
else if (tf.next.ty != Tvoid && !resType.toBasetype().isTypeNoreturn()) else if (tf.next.ty != Tvoid && !resType.toBasetype().isTypeNoreturn())
{ {
if (tf.next.ty != Terror) if (!tf.next.isTypeError())
{ {
error(rs.loc, "mismatched function return type inference of `void` and `%s`", tf.next.toChars()); error(rs.loc, "mismatched function return type inference of `void` and `%s`", tf.next.toChars());
} }
@ -2808,7 +2807,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
if (tbret.ty != Tvoid && !resType.isTypeNoreturn()) // if non-void return if (tbret.ty != Tvoid && !resType.isTypeNoreturn()) // if non-void return
{ {
if (tbret.ty != Terror) if (!tbret.isTypeError())
{ {
if (e0) if (e0)
error(rs.loc, "expected return type of `%s`, not `%s`", tret.toChars(), resType.toChars()); error(rs.loc, "expected return type of `%s`, not `%s`", tret.toChars(), resType.toChars());
@ -2902,7 +2901,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
} }
if (e0) if (e0)
{ {
if (e0.op == EXP.declaration || e0.op == EXP.comma) if (e0.isDeclarationExp() || e0.isCommaExp())
{ {
rs.exp = Expression.combine(e0, rs.exp); rs.exp = Expression.combine(e0, rs.exp);
} }