Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
vala
vala
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 702
    • Issues 702
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 39
    • Merge Requests 39
  • Operations
    • Operations
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Repository
    • Value Stream
  • External Wiki
    • External Wiki
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
  • GNOME
  • valavala
  • Issues
  • #892

Closed
Open
Opened Jan 07, 2020 by philippejer@philippejerContributor

Coalesce operator does not transfer ownership transitively

[Note: see MR !96 (merged)]

The coalesce expression uses the target type to detect that it needs to transfer ownership from the temporary local variable it creates under the hood.

But currently, it does not propagate its target type to the left or right expressions (unlike the conditional expression).

So in the following code test_direct() compiles and works but test_transitive() does not compile (error: duplicating Foo instance):

[Compact]
class Foo {
  public int n;

  public Foo (int n) {
    this.n = n;
  }
}

Foo? get_some_foo (int? n) {
  return n != null ? new Foo (n) : null;
}

void test_direct () {
  Foo f = get_some_foo (null) ?? get_some_foo (42);
  assert (f.n == 42);
}

void test_transitive () {
  Foo f = get_some_foo (null) ?? (get_some_foo (null) ?? get_some_foo (42));
  assert (f.n == 42);
}
Edited Jan 07, 2020 by philippejer
To upload designs, you'll need to enable LFS and have admin enable hashed storage. More information
Assignee
Assign to
0.48
Milestone
0.48
Assign milestone
Time tracking
None
Due date
None
Reference: GNOME/vala#892