New Type Solver: “Type … does not have key …” error after applying valid table inheritance

When trying to achieve inheritance through both standard Luau as well as custom types, attempting to access a property from an instance of the derived class will result in a Type <custom_class> does not have key <class_property> error.
Despite this error…

...autocomplete is perfectly capable of suggesting the 'instance' property I'm trying to reference

Steps to replicate (alternatively, download the attached place file):

  1. Set workspace.UseNewLuauTypeSolver to “Enabled”.
  2. (Optionally) Set workspace.LuauTypeCheckMode to “Strict”.
  3. Create two ModuleScript instances parented to the same folder:
    Base
    --!strict
    
    const Base = {}
    Base.__index = {}
    
    export type Class = setmetatable<{
        read instance: Instance,
    }, typeof(Base)>
    
    function Base.new(instance: Instance): Class
        return setmetatable({
            instance = instance,
        }, Base)
    end
    
    function Base.ChangeName(self: Class, name: string): ()
        error("Override required.")
    end
    
    return Base
    
    Derived
    --!strict
    
    const Base = require(script.Parent.Base)
    
    const Derived = setmetatable({}, Base)
    Derived.__index = Derived
    
    export type Class = setmetatable<Base.Class & {
        -- ...add new members here.
    }, typeof(Derived)>
    
    function Derived.new(instance: Instance): Class
        return table.freeze(setmetatable(Base.new(instance), Derived))
    end
    
    function Derived.ChangeName(self: Class, name: string): ()
        self.instance.Name = name -- TypeError: Type 'Class' does not have key 'instance'
    end
    
    return Derived
    
  4. :clap: you dun did it now

Repro62006667_Type does not have key.rbxl (60.2 KB)

System Information
CPU: 12th Gen Intel(R) Core(TM) i9-12900K (16+8)
GPU 1: NVIDIA RTX PRO 4000 Blackwell SFF Edition
GPU 2: Intel UHD Graphics 770 @ 1.55 GHz [Integrated]
Memory: 62.47 GiB

Expected behavior

Based on the example classes from earlier, I expect Derived to inherit the properties & functions of Base through the use of metatables. Each of these classes reside in their own ModuleScript instance and their types are referable through a <module>.Class syntax.
In the context of the issue example, self.instance should be a valid member of class Derived when self is type-hinted with its custom Class type, like autocomplete suggests.

As a side note, I have also previously made a post about this elsewhere asking for help, thinking I wasn’t doing something correctly.
I received no relevant response to my issue, so I have reason to believe it’s a bug.

Hello! Yeah this seems like it is a bug, or at least there’s something inconsistent here. As you note, autocomplete is suggesting something reasonable. We’ll triage this and get back to you when a fix rolls out.

1 Like