From b973602237581ebdaae7772c570c53c8093f59dc Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Fri, 20 Jan 2017 19:10:39 -0800 Subject: [PATCH] infer 'scope' for 'this' parameter --- src/func.d | 9 +++++++++ test/fail_compilation/retscope.d | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/func.d b/src/func.d index c6550876d35d..a3dbf527282b 100644 --- a/src/func.d +++ b/src/func.d @@ -2238,6 +2238,13 @@ extern (C++) class FuncDeclaration : Declaration } } + if (vthis && vthis.storage_class & STCmaybescope) + { + vthis.storage_class &= ~STCmaybescope; + vthis.storage_class |= STCscope; + f.isscope = true; + } + // reset deco to apply inference result to mangled name if (f != type) f.deco = null; @@ -2402,6 +2409,8 @@ extern (C++) class FuncDeclaration : Declaration if (tf.isscope) v.storage_class |= STCscope; } + if (flags & FUNCFLAGinferScope) + v.storage_class |= STCmaybescope; v.semantic(sc); if (!sc.insert(v)) diff --git a/test/fail_compilation/retscope.d b/test/fail_compilation/retscope.d index cfd63c580d54..5d321a308e57 100644 --- a/test/fail_compilation/retscope.d +++ b/test/fail_compilation/retscope.d @@ -589,3 +589,26 @@ void foo18() typeof(&c.funcrs) fs4 = &c.funcrs; } +/********************************************/ + + +bool foo20(const string a) @safe pure nothrow @nogc +{ + return !a.length; +} + +struct Result(R) +{ + R source; + + bool empty() // infer 'scope' for 'this' + { return foo20(source); } +} + +@safe void test20() +{ + scope n = Result!string("abc"); + n.empty(); +} + +