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

add with compound statement #20715

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

WalterBright
Copy link
Member

This was requested in the newsgroups. Adds the syntax:

{
    with (E):
       statement;
       statement;
}

which is equivalent to:

{
    with (E)
    {
       statement;
       statement;
    }
}

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @WalterBright!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#20715"

@thewilsonator thewilsonator added the Review:Needs Spec PR A PR updating the language specification needs to be submitted to dlang.org label Jan 16, 2025
@WalterBright
Copy link
Member Author

Spec PR dlang/dlang.org#4163

@WalterBright WalterBright removed the Review:Needs Spec PR A PR updating the language specification needs to be submitted to dlang.org label Jan 18, 2025
@ibuclaw
Copy link
Member

ibuclaw commented Jan 19, 2025

Note, these are accepted at global, but rejected at a scope level.

void example()
{
    { version(all): int decl; }
    { static if(cond): int decl; }
}   

Where does this sit with other kinds of statements that have ScopeStatement bodies, which don't get the same syntactical sugar treatment?

{
  if (cond):
    statement;
    statement;
}
{
  while (cond):
    statement;
    statement;
}
{
  do:
    statement;
    statement;
  while (cond);
}
{
  for (elem; list):
    statement;
}
{
  foreach (elem; list):
    statement;
}
{
  synchronized (object):
    statement;
}
{
  try:
    statement;
  catch (type):
    statement;
  finally:
    statement;
}
{
  switch (cond):
    case 1:
      break;
    default:
      break;
}

@WalterBright
Copy link
Member Author

A fair question. It only came up in the n.g. as a convenience wish for with. We also started with if (declaration), which was eventually generalized to switch (declaration), etc., once it proved its desirability. We can start with with: and see how it goes.

@nordlow
Copy link
Contributor

nordlow commented Jan 22, 2025

I have also been longing for allowing similar syntax for pragma(...) in my case specifically for

pragma(inline):
pragma(inline, false):
pragma(inline, true):

.

Is this possible to add support for?

@thewilsonator
Copy link
Contributor

pragma(ident): // influence subsequent declarations
    declaration;
    declaration;

https://dlang.org/spec/pragma.html That already works.

@nordlow
Copy link
Contributor

nordlow commented Jan 22, 2025

https://dlang.org/spec/pragma.html That already works.

Ahh. I forgot. Sorry for disturbing. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants