Skip to content

New Solver double assignment to a variable with a cast causes never refinements #1914

@OverHash

Description

@OverHash

Consider this code:

--!strict

type WallHolder = {
	__type: "Model",
	Wall: {
		__type: "BasePart",
		age: number,
	},
}

local walls = {
	{ name = "Part1" },
	{ name = "Part2" },
	{ name = "Wall" },
}

local baseWall: WallHolder?
for _, wall in walls do
	if wall.name == "Wall" then
		baseWall = wall :: WallHolder
	end
end
assert(baseWall, "Failed to get base wall when creating room props")

local myAge = baseWall.Wall.age

even though this code should be type safe, the last line has problems.

Specifically, baseWall on the last line is recognized as:

local baseWall: {
    Wall: {
        __type: "BasePart",
        age: number
    },
    ... 1 more ...
}

which is good! baseWall.Wall is also good:

{
    __type: "BasePart",
    age: number
}

however when we access baseWall.Wall.age, we get never!

This results in myAge having the type never, even though it should be number.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnew solverThis issue is specific to the new solver.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions