dart-lang / dart-lang/language

Should struct types work with `Expando` and `Finalizer`?

Open
#2,376 3 comments 0 reactions 0 assignees View on GitHub
brevity data-classes feature
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

Some objects are more object than other. There are classes where we do fiddle with identity, and we don't allow you to use those with features that depend on identity (currently `Expando`, `Finalizer` and `WeakReference`).

The problem so far has been that it's possible to have two separate objects with the same "identity". Even worse, it's possible to reintroduce an identical value *after* an old object has been GC'ed (for strings). That's such a mess that we just disallowed using those objects in places where identity *and* GC both matter.

Struct types, with their lax identity requirements, are different. It's not that we can introduce an identical struct later, it's more that we can't even know that we can present the same struct twice. It's a *safe and correct* implementation to throw away anything attached to a struct with an `Expando` immediately, because we don't even promise that the value has the same identity across calling `Expando.[]=`.

Should we disallow using struct types with `Expando`, `Finalizer` and `WeakReference`?

(Extension structs do not have their own identity, that belongs to the underlying object, so whatever we do should depend on the wrapped object, not the extension struct type.)

Contributor guide

Open the contributing guide

Research direction

The issue names no files, tests, or entry points; begin by reviewing the language rules for struct types, Expando, Finalizer, and WeakReference. Done means reaching and documenting a decision on whether struct types are allowed, including the stated extension-struct distinction.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.