Skip to content

Commit

Permalink
Add type coercion for Message and Color types
Browse files Browse the repository at this point in the history
  • Loading branch information
out-of-phaze committed Nov 8, 2024
1 parent d7f84e3 commit 2a2a6ed
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion DMCompiler/DM/DMValueType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ public DMComplexValueType(DMValueType type, DreamPath? typePath, (int, bool)[]?
public DMComplexValueType(DMValueType type, DreamPath? typePath, DMListValueTypes? listValueTypes) : this(type, typePath, null, listValueTypes) { }

public bool MatchesType(DMValueType type) {
return IsAnything || (Type & type) != 0;
if (IsAnything || (Type & type) != 0) return true;
if ((type & (DMValueType.Text | DMValueType.Message)) != 0 && (Type & (DMValueType.Text | DMValueType.Message)) != 0) return true;
if ((type & (DMValueType.Text | DMValueType.Color)) != 0 && (Type & (DMValueType.Text | DMValueType.Color)) != 0) return true;
return false;
}

public bool MatchesType(DMComplexValueType type) {
Expand All @@ -98,6 +101,12 @@ public bool MatchesType(DMComplexValueType type) {
}
}
}
// special case for color and lists:
if (type.Type.HasFlag(DMValueType.Color) && IsList && ListValueTypes?.NestedListKeyType.Type == DMValueType.Num && ListValueTypes.NestedListValType is null)
return true;
// probably only one of these is correct but i can't be assed to figure out which
if (Type.HasFlag(DMValueType.Color) && type.IsList && type.ListValueTypes?.NestedListKeyType.Type == DMValueType.Num && type.ListValueTypes.NestedListValType is null)
return true;
if (type.IsInstance && MatchesType(type.TypePath!.Value.GetAtomType())) {
return true;
}
Expand Down

0 comments on commit 2a2a6ed

Please sign in to comment.