The following code: ---- void outer(bool b) { string inner() { if (b) { return "true"; } else { return "false"; } } pragma(msg, inner()); } ---- Compiles and evaluates without error, despite the dependence on the runtime value b.
Extended test cases (applies to delegate literals as well as inner functions): void bug5396(int b) { int inner() { return b; } static int staticInner() { return 6; } static assert(is(typeof(compiles!( function int () { return 7; }() )))); static assert(!is(typeof(compiles!( delegate int () { return b; }() )))); static assert(!is(typeof(compiles!( inner() )))); static assert(is(typeof(compiles!( staticInner() )))); } Patch in interpret.c, CallExp::interpret(). Problem is, this breaks bug 1461 which seems to be an important use case. if (!istate && fd && fd->isNested() && !fd->isStatic() && /* BUG: Delegate literals report 'isNested()' even if they are * declared at module scope. */ !(fd->isFuncLiteralDeclaration() && !fd->toParent2()->isFuncDeclaration())) { error("cannot directly interpret non-static nested function %s", fd->toChars()); return EXP_CANT_INTERPRET; } if (pthis && fd) { // Member function call
https://github.com/D-Programming-Language/dmd/commit/04460186c70caa885935433138879d8684b1d14a
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル