Skip to content

Commit

Permalink
Type bounds: check trait and impl
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanjermakov committed Sep 10, 2024
1 parent ee3bd47 commit 2fa5403
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/phase/type-bound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export const collectTypeBounds = (node: AstNode, ctx: Context, parentBound?: Inf
collectTypeBounds(node.expr, ctx, node.varType ? node.varType : undefined)
}
collectTypeBounds(node.pattern, ctx, node.expr?.type)
node.type = instantiateDefType(ctx.stdTypeIds.unit?.type ?? makeErrorType('no def'))
node.type = instantiateDefType(ctx.stdTypeIds.unit?.type ?? makeErrorType('no def', 'no-def'))
break
}
case 'fn-def': {
Expand All @@ -226,7 +226,6 @@ export const collectTypeBounds = (node: AstNode, ctx: Context, parentBound?: Inf
}
case 'trait-def':
case 'impl-def': {
if (node.kind === 'impl-def' && node.forTrait) break
node.block.statements.forEach(s => collectTypeBounds(s, ctx))
// TODO
break
Expand Down
13 changes: 7 additions & 6 deletions src/phase/type-unify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,9 @@ export const unifyTypeBounds = (node: AstNode, ctx: Context, report = true): voi
}
break
}
case 'trait-def': {
// TODO
break
}
case 'trait-def':
case 'impl-def': {
// TODO
node.block.statements.forEach(s => unifyTypeBounds(s, ctx))
break
}
case 'method-call-op': {
Expand Down Expand Up @@ -179,7 +176,11 @@ export const unifyType = (type: InferredType, ctx: Context): void => {
break
case 'field-access':
unifyType(type.operandType, ctx)
if (type.operandType.kind === 'def' && type.operandType.def?.kind === 'type-def') {
if (type.operandType.kind === 'def') {
if (type.operandType.def?.kind !== 'type-def') {
unreachable()
break
}
const typeDef = type.operandType.def
if (typeDef.variants.length > 1) {
// TODO: make sure every variant contains such field with equal type
Expand Down

0 comments on commit 2fa5403

Please sign in to comment.