Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • vala vala
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 770
    • Issues 770
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 73
    • Merge requests 73
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GNOMEGNOME
  • valavala
  • Merge requests
  • !134

Anonymous delegates

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Nick Schrader requested to merge nschrader/vala:wip/issue/658 into master Jul 20, 2020
  • Overview 21
  • Commits 29
  • Pipelines 0
  • Changes 24

Final implementation for issue #658.

This PR implements anonymous delegates to be exclusively used as parameter types. They are a simplified expression for named delegates, but do not support all their language features. Inner parameters are anonymous (without identifier) to be even more short-hand.

void f (delegate(int, int) => int d) {
   stdout.printf ("%d\n", d(1, 2));
}

void main () {
   f ((a, b) => a + b);
}

Restrictions are:

  • no throws-clause, named delegates should be preferred in this case
  • anonymous delegates cannot return an anonymous delegate, named delegates should be preferred in this case
  • outer dynamic and params modifiers are not allowed, as they would require arrays of anonymous delegates and run-time information that is unavailable to this implementation
  • outer ref and out modifiers are not permitted as they would require the anonymous type to be reused elsewhere
  • inner ref, out, unowned and weak modifiers are allowed
  • no inner dynamic and params modifiers, named delegates should be preferred in this case
  • inner optional parameters are not permitted as the argument would need to be named and not anonymous to retrieve the default value
  • inner and outer code attributes are accepted, but a warning is thrown if they are ambiguous (void f([CCode (scope = "async")] delegate() => void d) could apply to the parameter d or the anonymous delegate; in doubt it is always applied to the parameter)

Moreover, the following functionalities come along:

  • warning saying that anonymous delegates are still experimental
  • meaningful error messages
  • pretty printing of anonymous delegates in compiler messages
  • updated (and tested) CodeWriter
  • 20 tests
Edited Nov 06, 2020 by Nick Schrader
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: wip/issue/658