Skip to content

Commit

Permalink
Fixed #218, checking for list types on spread operators.
Browse files Browse the repository at this point in the history
  • Loading branch information
amyjko committed Oct 24, 2023
1 parent 59b4d6d commit c2aebf5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/locale/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand Down
11 changes: 11 additions & 0 deletions src/nodes/ListLiteral.test.ts
Original file line number Diff line number Diff line change
@@ -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);
}
);
20 changes: 18 additions & 2 deletions src/nodes/Spread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c2aebf5

Please sign in to comment.