@@ -1194,15 +1194,18 @@ private bool checkReturnEscapeImpl(Scope* sc, Expression e, bool refs, bool gag)
11941194
11951195 Dsymbol p = v.toParent2();
11961196
1197- if ((v.isScope() || (v.storage_class & STC .maybescope)) &&
1198- ! (v.storage_class & STC .return_) &&
1197+ bool needsReturn = false ;
1198+ if ( ! (v.storage_class & STC .return_) &&
11991199 v.isParameter() &&
1200- ! v.doNotInferReturn &&
1201- sc.func.flags & FUNCFLAG .returnInprocess &&
12021200 p == sc.func)
12031201 {
1204- inferReturn(sc.func, v); // infer addition of 'return'
1205- continue ;
1202+ if ((v.isScope() || (v.storage_class & STC .maybescope)) &&
1203+ sc.func.flags & FUNCFLAG .returnInprocess)
1204+ {
1205+ inferReturn(sc.func, v); // infer addition of 'return'
1206+ continue ;
1207+ }
1208+ needsReturn = true ; // needs 'return' annotation on parameter
12061209 }
12071210
12081211 if (v.isScope())
@@ -1249,6 +1252,17 @@ private bool checkReturnEscapeImpl(Scope* sc, Expression e, bool refs, bool gag)
12491252 result = false ;
12501253 }
12511254 }
1255+ else if (needsReturn && sc.func.type.isTypeFunction().purity != PURE .impure && global.params.vsafe &&
1256+ sc._module && sc._module.isRoot())
1257+ {
1258+ /* Pure functions assume their parameters are `scope`, but they don't assume `return`.
1259+ * Hence, the annotation needs to be explicit.
1260+ */
1261+ if (! gag)
1262+ error(e.loc, " `pure` function `%s` returns parameter `%s`, annotate with `return`" ,
1263+ sc.func.ident.toChars(), v.toChars());
1264+ result = true ;
1265+ }
12521266 else
12531267 {
12541268 // printf("no infer for %s in %s, %d\n", v.toChars(), sc.func.ident.toChars(), __LINE__);
0 commit comments