Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML fields of type color can accept strings or integers #1016

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/XmlScope.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { createSandbox } from 'sinon';
import { ComponentType } from './types/ComponentType';
import { SymbolTypeFlag } from './SymbolTable';
import { AssociativeArrayType } from './types/AssociativeArrayType';
import { ArrayType, BooleanType, DoubleType, DynamicType, FloatType, IntegerType, StringType, TypedFunctionType } from './types';
import { ArrayType, BooleanType, DoubleType, DynamicType, FloatType, IntegerType, StringType, TypedFunctionType, UnionType } from './types';
const sinon = createSandbox();

describe('XmlScope', () => {
Expand Down Expand Up @@ -238,10 +238,14 @@ describe('XmlScope', () => {
expectTypeToBe((widgetType.getMemberType('isIntArray', { flags: SymbolTypeFlag.runtime }) as ArrayType).defaultType, IntegerType);

expectTypeToBe(widgetType.getMemberType('isBool', { flags: SymbolTypeFlag.runtime }), BooleanType);
expectTypeToBe(widgetType.getMemberType('isColor', { flags: SymbolTypeFlag.runtime }), IntegerType);

expectTypeToBe(widgetType.getMemberType('isColor', { flags: SymbolTypeFlag.runtime }), UnionType);
let colorType = widgetType.getMemberType('isColor', { flags: SymbolTypeFlag.runtime }) as UnionType;
expect(colorType.types).to.include(StringType.instance);
expect(colorType.types).to.include(IntegerType.instance);

expectTypeToBe(widgetType.getMemberType('isColorArray', { flags: SymbolTypeFlag.runtime }), ArrayType);
expectTypeToBe((widgetType.getMemberType('isColorArray', { flags: SymbolTypeFlag.runtime }) as ArrayType).defaultType, IntegerType);
expectTypeToBe((widgetType.getMemberType('isColorArray', { flags: SymbolTypeFlag.runtime }) as ArrayType).defaultType, UnionType);

expectTypeToBe(widgetType.getMemberType('isVector2d', { flags: SymbolTypeFlag.runtime }), ArrayType);
expectTypeToBe((widgetType.getMemberType('isVector2d', { flags: SymbolTypeFlag.runtime }) as ArrayType).defaultType, FloatType);
Expand Down
13 changes: 10 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { ComponentType } from './types/ComponentType';
import { MAX_RELATED_INFOS_COUNT } from './diagnosticUtils';
import { BinaryOperatorReferenceType } from './types/ReferenceType';
import type { UnresolvedSymbol } from './AstValidationSegmenter';
import { unionTypeFactory } from './types/UnionType';

export class Util {
public clearConsole() {
Expand Down Expand Up @@ -1206,6 +1207,10 @@ export class Util {
return rect2dType;
}

function getColorType() {
return unionTypeFactory([IntegerType.instance, StringType.instance]);
}


if (typeDescriptorLower.startsWith('array of ')) {
let arrayOfTypeName = typeDescriptorLower.substring(9); //cut off beginning 'array of'
Expand All @@ -1228,13 +1233,15 @@ export class Util {
} else if (typeDescriptorLower === 'uri') {
return StringType.instance;
} else if (typeDescriptorLower === 'color') {
return IntegerType.instance;
return getColorType();
} else if (typeDescriptorLower === 'vector2d' || typeDescriptorLower === 'floatarray') {
return new ArrayType(FloatType.instance);
} else if (typeDescriptorLower === 'vector2darray') {
return new ArrayType(new ArrayType(FloatType.instance));
} else if (typeDescriptorLower === 'intarray' || typeDescriptorLower === 'colorarray') {
} else if (typeDescriptorLower === 'intarray') {
return new ArrayType(IntegerType.instance);
} else if (typeDescriptorLower === 'colorarray') {
return new ArrayType(getColorType());
} else if (typeDescriptorLower === 'boolarray') {
return new ArrayType(BooleanType.instance);
} else if (typeDescriptorLower === 'stringarray' || typeDescriptorLower === 'strarray') {
Expand All @@ -1249,7 +1256,7 @@ export class Util {
return BooleanType.instance;
} else if (typeDescriptorLower === 'array') {
return new ArrayType();
} else if (typeDescriptorLower === 'assocarray' || typeDescriptorLower === 'associative array') {
} else if (typeDescriptorLower === 'assocarray' || typeDescriptorLower === 'associative array' || typeDescriptorLower === 'associativearray') {
return new AssociativeArrayType();
} else if (typeDescriptorLower === 'node') {
return ComponentType.instance;
Expand Down