Skip to content

Subtyping: better errors - #236

Merged
faiface merged 16 commits into
mainfrom
subtyping-better-errors
Aug 7, 2026
Merged

Subtyping: better errors#236
faiface merged 16 commits into
mainfrom
subtyping-better-errors

Conversation

@NoamDev

@NoamDev NoamDev commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

fixes #219

This PR introduces better error messages for subtyping failures.

Examples:

image image image image image

Try par check on the following example to reproduce yourself:

module Main

import @core/Int
import @core/String


type Point = either { .a Int, .b String }

def T: [Point] either {} = [x] x

def T2: [[!,<a,b,c>!, !]!][!,<a,b>!, !]! = [x] x

def T3: [[type a: box]!][type b]! = [x]x

def T4: [(type a)!](type b: box)! = [x]x

def T5: [[<a: box>!]!][<b>!]! = [x]x

type Functor<s> = either {.a choice {.b => s}}

def T6: [iterative either {.a choice {.b => self}}]recursive either {.a choice {.b => self}} = [x] x

type Inner<s> =
	choice {
		.none => recursive either {
			.get s,
			.result self,
		}
	}


type ReadP =
	iterative@get
	Inner<self@get>


dec ForceCast :
	[
		Inner<ReadP>
	]
	ReadP
def ForceCast = [p] p


dec Bind :
	[ReadP]
	ReadP
def Bind =
	[p]
	chan res {
		res.begin@get
		p.none.begin
		p.case {
			.get p => {
				res.case {
					.none => {
						res.get
						res.loop@get
					},
				}
			},
			.result p => {
				let foo = chan res {
					p.loop
				}
				let bar = ForceCast(foo)
				res <> bar
			},
		}
	}

def T9: either{} = chan res {
    let x: recursive ! = !
    x.begin
    let x: recursive ! = !
    {loop} <> x
} 

@faiface faiface left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me now! Thank you so much.

@faiface
faiface merged commit 7169ee6 into main Aug 7, 2026
3 checks passed
@faiface
faiface deleted the subtyping-better-errors branch August 16, 2026 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typechecker bug regarding complex recursive/iterative types

2 participants