Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/dmd/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -2864,7 +2864,8 @@ final class Parser(AST) : Lexer
// Don't call nextToken again.
}
case TOK.in_:
stc = STC.in_;
// `in` now means `const scope` as originally intented
stc = STC.const_ | STC.scope_;
goto L2;

case TOK.out_:
Expand Down
8 changes: 7 additions & 1 deletion src/dmd/semantic3.d
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,14 @@ private extern(C++) final class Semantic3Visitor : Visitor
stc |= STC.scope_;
}
}
if (funcdecl.flags & FUNCFLAG.inferScope && !(fparam.storageClass & STC.scope_))

// infer scope for lambdas even without -preview=dip1000
// See https://issues.dlang.org/show_bug.cgi?id=20362
const isLambda = funcdecl.isFuncLiteralDeclaration;

if ((funcdecl.flags & FUNCFLAG.inferScope || isLambda) && !(fparam.storageClass & STC.scope_))
stc |= STC.maybescope;

stc |= fparam.storageClass & (STC.in_ | STC.out_ | STC.ref_ | STC.return_ | STC.scope_ | STC.lazy_ | STC.final_ | STC.TYPECTOR | STC.nodtor);
v.storage_class = stc;
v.dsymbolSemantic(sc2);
Expand Down
4 changes: 2 additions & 2 deletions test/compilable/extra-files/header2.di
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class C
{
}
void foo(const C c, const(char)[] s, const int* q, const(int*) p);
void bar(in void* p);
void bar(scope const void* p);
void f(void function() f2);
class C2;
void foo2(const C2 c);
Expand Down Expand Up @@ -93,7 +93,7 @@ void foo11217()(auto ref int[] arr)
void foo11217()(scope int[] arr)
{
}
void foo11217()(in int[] arr)
void foo11217()(scope const int[] arr)
{
}
void foo11217()(inout int[] arr)
Expand Down
4 changes: 2 additions & 2 deletions test/compilable/extra-files/header2i.di
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class C
void foo(const C c, const(char)[] s, const int* q, const(int*) p)
{
}
void bar(in void* p)
void bar(scope const void* p)
{
}
void f(void function() f2);
Expand Down Expand Up @@ -106,7 +106,7 @@ void foo11217()(auto ref int[] arr)
void foo11217()(scope int[] arr)
{
}
void foo11217()(in int[] arr)
void foo11217()(scope const int[] arr)
{
}
void foo11217()(inout int[] arr)
Expand Down
13 changes: 13 additions & 0 deletions test/compilable/test_in_scope_const.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* REQUIRED_ARGS: -preview=dip1000
*/

@safe:

import std.traits: ParameterStorageClassTuple, ParameterStorageClass, Parameters;

void fun(in int* inParam);
alias storages = ParameterStorageClassTuple!fun;
alias storage = storages[0];

static assert(is(Parameters!fun[0] == const int*));
static assert(storage & ParameterStorageClass.scope_);
2 changes: 1 addition & 1 deletion test/fail_compilation/fail183.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ TEST_OUTPUT:
---
fail_compilation/fail183.d(10): Error: redundant attribute `const`
fail_compilation/fail183.d(10): Error: redundant attribute `scope`
fail_compilation/fail183.d(11): Error: redundant attribute `in`
fail_compilation/fail183.d(11): Error: redundant attribute `scope const`
---
*/

Expand Down