diff --git a/src/locale/en-US.json b/src/locale/en-US.json index b0256dd54..648734c26 100644 --- a/src/locale/en-US.json +++ b/src/locale/en-US.json @@ -413,7 +413,7 @@ "secondary": "I have has the same name as $1" }, "IncompatibleType": { - "primary": "I'm supposed to be $2, but I'm $1", + "primary": "I'm supposed to be a $2, but I'm a $1", "secondary": "Oh… sorry, a $1, really?" }, "MisplacedShare": "I can only share things at the @Program level, not inside anything!", diff --git a/src/nodes/ListLiteral.test.ts b/src/nodes/ListLiteral.test.ts new file mode 100644 index 000000000..28d92c5a7 --- /dev/null +++ b/src/nodes/ListLiteral.test.ts @@ -0,0 +1,11 @@ +import { test } from 'vitest'; +import { testConflict } from '@conflicts/TestUtilities'; +import IncompatibleType from '../conflicts/IncompatibleType'; +import Spread from './Spread'; + +test.each([['num: [1] [1 :num]', 'num: 2 [1 :num]', Spread, IncompatibleType]])( + 'Expect %s no conflicts, %s to have %s with %s', + (good, bad, node, conflict) => { + testConflict(good, bad, node, conflict); + } +); diff --git a/src/nodes/Spread.ts b/src/nodes/Spread.ts index c8a6456b4..7fc537e87 100644 --- a/src/nodes/Spread.ts +++ b/src/nodes/Spread.ts @@ -10,6 +10,9 @@ import { BIND_SYMBOL } from '../parser/Symbols'; import AnyType from './AnyType'; import ListType from './ListType'; import type Locales from '../locale/Locales'; +import type Context from './Context'; +import IncompatibleType from '../conflicts/IncompatibleType'; +import type Conflict from '../conflicts/Conflict'; /** Inside a list literal, flattens values of a list value into a new list */ export default class Spread extends Node { @@ -63,8 +66,21 @@ export default class Spread extends Node { return 'list'; } - computeConflicts() { - return; + computeConflicts(context: Context): Conflict[] { + if (this.list) { + const type = this.list.getType(context); + if (!(type instanceof ListType)) + return [ + new IncompatibleType( + this, + ListType.make(), + this.list, + type + ), + ]; + } + + return []; } getNodeLocale(locales: Locales) {