Record what MATLAB does when the default enumeral is deleted - #35
Merged
Merged
Conversation
Two probes and the measurement they produced. The question: an enum has item1,
item2, item3 with DefaultValue 'item2'; the user deletes item2. Should the
displayed Value change?
MATLAB says yes, and the two dictionary flavours get there differently:
Architectural Data DefaultValue immediately reads the first surviving
enumeral. It is a clear-and-fall-back, not a re-point --
remove that one too and the default follows along. Also
refuses to delete the last enumeral at all.
Design Data the live object keeps the dangling name, but saving DROPS
the key, so a reload reports '' and the effective default
is the first survivor.
Neither ever persists a DefaultValue naming an enumeral the file lacks. Both
validate the name on assignment and neither re-validates on removal.
We keep the dangling name: the Value column shows the deleted enumeral, no
enumeral gets the "current" icon, the dropdown displays a value outside its own
options, and we write that DefaultValue into the file. Handing MATLAB the file
our writer produces settles the severity -- it opens without error and silently
repairs the default, in both .sldd formats, each checked in its own MATLAB
session because two dictionaries defining the same enum in one session make
MATLAB reuse the first definition. So this is a display and round-trip fidelity
defect rather than corruption, and it is written up in the class doc with the fix
identified and explicitly not yet applied.
The probes also correct two API guesses worth keeping on record: design data
appends with appendEnumeral and removes by INDEX, arch data adds with
addEnumeral and removes by NAME, and neither add takes a bare name.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The question
An
EnumTypehasitem1,item2,item3and itsDefaultValueisitem2.The user deletes
item2. Should the displayed Value change?Measured answer — yes, and the two flavours differ
Probed against MATLAB R2027a Prerelease 27.1.0.3393633.
EnumTypeDefinition)archdata.EnumType)CannotDeleteLastEnumeral)DynamicEnum_InvalidDefaultValue)''→ first enumeralBoth converge on the effective default becomes the first surviving enumeral, and
neither ever persists a
DefaultValuenaming an absent enumeral. Design data justdefers the tidy-up to save time.
Where we differ, and how bad it is
We keep the dangling name, so the Value column shows the deleted enumeral, no
enumeral gets the "current" icon, the dropdown displays a value outside its own
options, and we write that
DefaultValueinto the file.Rather than assume the severity, the file our writer produces was handed to
MATLAB: it opens without error and silently repairs the default — both .sldd
formats, each in its own MATLAB session, because two dictionaries defining the same
enum in one session make MATLAB reuse the first definition and contaminate the
second result. So it is a display and round-trip fidelity defect, not corruption.
What is in this PR
Documentation and probes only — no behaviour change, no
dist/change. The fix isidentified in
Simulink.EnumType.mdand explicitly marked not implemented, so thechange to make it is a separate, reviewable commit.
Also on record: design data appends with
appendEnumeraland removes by index;arch data adds with
addEnumeraland removes by name; neither add accepts abare name.