Skip to content

Add detection of conflicting global type redefinitions#1127

Open
tyulpan wants to merge 1 commit into
teal-language:mainfrom
tyulpan:global-type-redefinitions
Open

Add detection of conflicting global type redefinitions#1127
tyulpan wants to merge 1 commit into
teal-language:mainfrom
tyulpan:global-type-redefinitions

Conversation

@tyulpan

@tyulpan tyulpan commented May 30, 2026

Copy link
Copy Markdown

Initially, I ran into the crash described in #1126.
My first idea was to simply ignore duplicate declarations. That would be fine for identical types.

But what if we wanted to do something like this:

global record Widget
  id: integer
end

global record Gadget
  name: string
end

global type Handle = Widget
global type Handle = Gadget

Simply ignoring the duplicate declaration would be a footgun here.

And that's where I ran into another problem. Related to #1032. Currently, redeclaring a global type (record, interface, or type alias) with a different definition isn't reported as an error, and the compiler keeps the first one it finds.

So let's fix that.

Resolves #1126.

Comment thread teal/check/relations.tl
},
["typedecl"] = {
["typedecl"] = function(ck: TypeChecker, a: TypeDeclType, b: TypeDeclType): boolean, {Error}
return ck:same_type(a.def, b.def)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The one thing I need to check about this PR is: are we sure that adding this does not accidentally introduce structural type compatibility to an otherwise mostly-nominal type system?

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.

Redeclaring a global type alias crashes the compiler

2 participants