Skip to content

Primary Type Syntax #3616

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

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
9 changes: 6 additions & 3 deletions spec/traits.dd
Original file line number Diff line number Diff line change
Expand Up @@ -1733,13 +1733,16 @@ static assert(__traits(isSame, foo, daz));
)

$(P The result is `true` if the two arguments are expressions
made up of literals or enums that evaluate to the same value.)
none of which are just symbols
that evaluate to the same value at compile-time.)

$(SPEC_RUNNABLE_EXAMPLE_COMPILE
---
enum e = 3;
static assert(__traits(isSame, (e), 3));
static assert(__traits(isSame, 5, 2 + e));
static assert(!__traits(isSame, e, 3)); // e is a symbol
static assert(!__traits(isSame, (e), 3)); // (e) is a symbol
static assert( __traits(isSame, cast(typeof(e)) e, 3)); // cast is an expression
static assert( __traits(isSame, 5, 2 + e)); // 5 and 2 + e are expressions
---
)
$(P If the two arguments are both
Expand Down
6 changes: 5 additions & 1 deletion spec/type.dd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ $(H2 $(LNAME2 grammar, Grammar))
$(GRAMMAR
$(GNAME Type):
$(GLINK TypeCtors)$(OPT) $(GLINK BasicType) $(GLINK TypeSuffixes)$(OPT)
$(D ref) $(GLINK TypeCtors)$(OPT) $(GLINK BasicType) $(GLINK CallableSuffix) $(GLINK TypeSuffixes)$(OPT)

$(GNAME TypeCtors):
$(GLINK TypeCtor)
Expand All @@ -30,7 +31,7 @@ $(GNAME BasicType):
$(GLINK QualifiedIdentifier)
$(GLINK Typeof)
$(GLINK Typeof) $(D .) $(GLINK QualifiedIdentifier)
$(GLINK TypeCtor) $(D $(LPAREN)) $(GLINK Type) $(D $(RPAREN))
$(GLINK TypeCtor)$(OPT) $(D $(LPAREN)) $(GLINK Type) $(D $(RPAREN))
$(GLINK Vector)
$(GLINK2 traits, TraitsExpression)
$(GLINK MixinType)
Expand Down Expand Up @@ -77,6 +78,9 @@ $(GNAME TypeSuffix):
$(D [) $(GLINK2 expression, AssignExpression) $(D ])
$(D [) $(GLINK2 expression, AssignExpression) $(D ..) $(GLINK2 expression, AssignExpression) $(D ])
$(D [) $(GLINK Type) $(D ])
$(GLINK CallableSuffix)

$(GNAME CallableSuffix):
$(D delegate) $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT)
$(D function) $(GLINK2 function, Parameters) $(GLINK2 function, FunctionAttributes)$(OPT)

Expand Down