diff --git a/src/phase/type-unify.ts b/src/phase/type-unify.ts index 58a71c9..dff4e44 100644 --- a/src/phase/type-unify.ts +++ b/src/phase/type-unify.ts @@ -256,7 +256,6 @@ const unify_ = (a: InferredType, b: InferredType, ctx: Context): InferredType => return b } switch (b.kind) { - // biome-ignore lint: case 'identifier': { if (a.def && a.def === b.def) { if (a.typeArgs.length === b.typeArgs.length) { @@ -273,6 +272,15 @@ const unify_ = (a: InferredType, b: InferredType, ctx: Context): InferredType => return u } } + if (a.def?.kind === 'type-def' && b.def?.kind === 'type-def') { + const e = makeErrorType( + `failed unify [${[a, b].map(t => inferredTypeToString(t)).join(', ')}]`, + 'no-unify' + ) + assign(a, e) + assign(b, e) + return e + } if (a.def?.kind === 'type-param') { if (a.def.unified) { const u = unify(a.def.unified, b, ctx) @@ -285,17 +293,18 @@ const unify_ = (a: InferredType, b: InferredType, ctx: Context): InferredType => return b } } + break } case 'inferred-fn': case 'fn-type': case 'name': const e = makeErrorType( - `failed unify [${[a, b].map(t => `${inferredTypeToString(t)} (${t.kind})`).join(', ')}]`, + `failed unify [${[a, b].map(t => inferredTypeToString(t)).join(', ')}]`, 'no-unify' ) assign(a, e) assign(b, e) - return a + return e } break } diff --git a/src/semantic/index.ts b/src/semantic/index.ts index adc7a4d..6be3f70 100644 --- a/src/semantic/index.ts +++ b/src/semantic/index.ts @@ -27,11 +27,4 @@ export const semanticCheck = (ctx: Context): void => { unifyTypeBounds ] phases.forEach(f => eachModule(f, ctx)) - // ;[collectTypeBounds, unifyTypeBounds].forEach(f => - // ctx.packages.at(-1)!.modules.forEach(m => { - // ctx.moduleStack.push(m) - // f(m, ctx) - // ctx.moduleStack.pop() - // }) - // ) } diff --git a/src/typecheck/index.ts b/src/typecheck/index.ts index 3b3404d..b42921f 100644 --- a/src/typecheck/index.ts +++ b/src/typecheck/index.ts @@ -135,7 +135,7 @@ export const inferredTypeToString = (t: InferredType, depth = 0): string => { case 'inferred': return `[${t.bounds.map(b => inferredTypeToString(b, depth + 1)).join(', ')}]` case 'inferred-fn': - const tps = t.typeParams.length > 0 ? `<${t.typeParams.map(typeParamToString)}>` : '' + const tps = t.typeParams.length > 0 ? `<${t.typeParams.map(typeParamToString).join(', ')}>` : '' const pts = t.params .map(pt => `${pt.name ? `${pt.name}: ` : ''}${inferredTypeToString(pt.type)}`) .join(', ') @@ -162,7 +162,7 @@ export const typeToString = (t: Type): string => { case 'identifier': return idToString(t) case 'fn-type': - const tps = t.typeParams.length > 0 ? `<${t.typeParams.map(typeParamToString)}>` : '' + const tps = t.typeParams.length > 0 ? `<${t.typeParams.map(typeParamToString).join(', ')}>` : '' const pts = t.params .map(pt => `${pt.name ? `${pt.name.value}: ` : ''}${typeToString(pt.paramType)}`) .join(', ')