Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[broken] Support TypeQual(TypeSeq) #16439

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions compiler/src/dmd/mtype.d
Original file line number Diff line number Diff line change
Expand Up @@ -4558,6 +4558,46 @@
{
v.visit(this);
}

override final Type makeConst()
{
if (mcache && mcache.cto)
{
assert(mcache.cto.isConst());
return mcache.cto;

Check warning on line 4567 in compiler/src/dmd/mtype.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/mtype.d#L4566-L4567

Added lines #L4566 - L4567 were not covered by tests
}
TypeTuple t = cast(TypeTuple) Type.makeConst();
if (arguments)
{
t.arguments = new Parameters(arguments.length);
foreach (i, ref arg; *t.arguments)
{
auto tsrc = (*arguments)[i].type;
arg = new Parameter(Loc.initial, 0, tsrc.addSTC(STC.const_), null, null, null);
}
}
return t;
}

override final Type makeImmutable()
{
if (mcache && mcache.ito)
{
assert(mcache.ito.isImmutable());
return mcache.ito;

Check warning on line 4587 in compiler/src/dmd/mtype.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/mtype.d#L4586-L4587

Added lines #L4586 - L4587 were not covered by tests
}
TypeTuple t = cast(TypeTuple) Type.makeImmutable();
if (arguments)
{
t.arguments = new Parameters(arguments.length);
foreach (i, ref arg; *t.arguments)
{
auto tsrc = (*arguments)[i].type;
arg = new Parameter(Loc.initial, 0, tsrc.immutableOf(), null, null, null);
}
}
return t;
}
}

/***********************************************************
Expand Down
16 changes: 16 additions & 0 deletions compiler/test/compilable/type_seq_qual.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
alias AliasSeq(Args...) = Args;

immutable(AliasSeq!(int, float)) c;
immutable AliasSeq!(int, float) d;
static assert(is(typeof(c) == typeof(d)));

alias TS = AliasSeq!(int, float);
static assert(is(typeof(c) == immutable TS));
static assert(is(immutable(TS)[0] == immutable int));
ntrel marked this conversation as resolved.
Show resolved Hide resolved

static assert(is(const(TS) == const TS));
static assert(is(const(AliasSeq!(int, float))[0] == const int)); // OK
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line actually fails too:

compilable/type_seq_qual.d(12): Error: static assert:  `is(const(int) == const(int))` is false

static assert(is(const(TS)[0] == const int)); // fails

alias CT = const(TS);
static assert(is(CT[0] == const int));