Skip to content

Commit a4977b7

Browse files
authored
Merge pull request #5 from mkantor/miscellanea
Miscellaneous trivial improvements
2 parents 9e1424f + d059e1b commit a4977b7

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

src/end-to-end.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ testCases(endToEnd, code => code)('end-to-end tests', [
6363
['{ (a: :(")")), (")": (B)) }', either.makeRight({ a: 'B', ')': 'B' })],
6464
[':match({ a: A })({ tag: a, value: {} })', either.makeRight('A')],
6565
[':{string concatenate}(a)(b)', either.makeRight('ba')],
66+
[
67+
':flow({ :string.concatenate(a) :string.concatenate(b) })(z)',
68+
either.makeRight('zab'),
69+
],
6670
[
6771
`{
6872
"static data":"blah blah blah"
@@ -212,4 +216,12 @@ testCases(endToEnd, code => code)('end-to-end tests', [
212216
value: 'true',
213217
}),
214218
],
219+
[
220+
`:integer.add(
221+
:integer.subtract(1)(2)
222+
)(
223+
:integer.subtract(2)(4)
224+
)`,
225+
either.makeRight('3'),
226+
],
215227
])

src/language/compiling/semantics/prelude.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,6 @@ export const prelude: ObjectNode = makeObjectNode({
308308
),
309309

310310
boolean: makeObjectNode({
311-
true: 'true',
312-
false: 'false',
313311
is: preludeFunction(
314312
['boolean', 'is'],
315313
{

src/language/parsing/molecule.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,16 @@ const sugaredApply: Parser<PartialMolecule> = parser.map(
9090
parser.oneOrMore(
9191
parser.sequence([
9292
parser.literal('('),
93+
optional(omit(whitespace)),
9394
parser.lazy(() => propertyValue),
95+
optional(omit(whitespace)),
9496
parser.literal(')'),
9597
]),
9698
),
9799
]),
98100
([f, multipleArguments]) =>
99101
multipleArguments.reduce<PartialMolecule>(
100-
(expression, [_1, argument, _2]) => ({
102+
(expression, [_1, _2, argument, _3, _4]) => ({
101103
0: '@apply',
102104
function: expression,
103105
argument,

src/language/semantics/type-system/subtyping.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,12 @@ const isNonUnionAssignableToUnion = ({
232232
if (source.kind === 'opaque') {
233233
return source.isAssignableTo(target)
234234
} else {
235-
// The strategy for this case is to check whether any of the target's members are
236-
// assignable to the source type. However this alone is not sufficient—for example
237-
// `{ a: 'a' | 'b' }` should be assignable to `{ a: 'a' } | { a: 'b' }` even though
238-
// `{ a: 'a' | 'b' }` is not directly assignable to `{ a: 'a' }` nor `{ a: 'b' }`. To
239-
// make things work the target type is first converted into a standard form (e.g.
240-
// `{ a: 'a' } | { a: 'b' }` is translated into `{ a: 'a' | 'b' }`.
235+
// The strategy for this case is to check whether any of the target's members are assignable to
236+
// the source type. However this alone is not sufficient—for example `{ a: 'a' | 'b' }` should
237+
// be assignable to `{ a: 'a' } | { a: 'b' }` even though `{ a: 'a' | 'b' }` is not directly
238+
// assignable to `{ a: 'a' }` nor `{ a: 'b' }`. To make things work the target type is first
239+
// converted into a standard form (e.g. `{ a: 'a' } | { a: 'b' }` is translated into
240+
// `{ a: 'a' | 'b' }`.
241241

242242
const preparedTarget = simplifyUnionType(target)
243243

@@ -290,20 +290,18 @@ export const simplifyUnionType = (typeToSimplify: UnionType): UnionType => {
290290
const reducibleSubsets: Map<
291291
string,
292292
{
293-
readonly keys: string[]
293+
readonly keys: readonly string[]
294294
readonly typesToMerge: Set<ObjectType>
295295
}
296296
> = new Map()
297297
for (const type of typeToSimplify.members) {
298298
if (typeof type !== 'string' && type.kind === 'object') {
299299
const keys = Object.keys(type.children)
300300

301-
// Object types with a single key are always mergeable with other object types
302-
// containing the same single key. For example `{ a: 'a' } | { a: 'b' }` can become
303-
// `{ a: 'a' | 'b' }`.
304-
// TODO: Handle cases where there is more than one key but property types are
305-
// compatible. For example `{ a: 'a', b: 'b' } | { a: 'b', b: 'b' }` can become
306-
// `{ a: 'a' | 'b', b: 'b' }`.
301+
// Object types with a single key are always mergeable with other object types containing the
302+
// same single key. For example `{ a: 'a' } | { a: 'b' }` can become `{ a: 'a' | 'b' }`.
303+
// TODO: Handle cases where there is more than one key but property types are compatible. For
304+
// example `{ a: 'a', b: 'b' } | { a: 'b', b: 'b' }` can become `{ a: 'a' | 'b', b: 'b' }`.
307305
const fingerprint = keys[0]
308306
if (keys.length === 1 && fingerprint !== undefined) {
309307
const objectTypesWithThisFingerprint = reducibleSubsets.get(
@@ -319,6 +317,7 @@ export const simplifyUnionType = (typeToSimplify: UnionType): UnionType => {
319317

320318
const canonicalizedTargetMembers: Set<Atom | Exclude<Type, UnionType>> =
321319
new Set([...typeToSimplify.members])
320+
322321
// Reduce `reducibleSubsets` by merging all candidate, updating `canonicalizedTargetMembers`.
323322
// Merge algorithm:
324323
// - for each reducible subset of object types:

0 commit comments

Comments
 (0)