Skip to content

Read-only/Write-only extern properties, Read-only vector properties#2071

Open
PhoenixWhitefire wants to merge 25 commits intoluau-lang:masterfrom
PhoenixWhitefire:readonly-extern-props
Open

Read-only/Write-only extern properties, Read-only vector properties#2071
PhoenixWhitefire wants to merge 25 commits intoluau-lang:masterfrom
PhoenixWhitefire:readonly-extern-props

Conversation

@PhoenixWhitefire
Copy link
Contributor

@PhoenixWhitefire PhoenixWhitefire commented Oct 31, 2025

Implements the read and write property attributes for external type definitions, which the embedded vector type now makes use of:

Before:

declare extern type vector with
    x: number
    y: number
    z: number
end

After:

declare extern type vector with
    read x: number
    read y: number
    read z: number
end

The following code now creates type-errors in the expected places:

--!strict
local function increment(v: vector)
    v.x += 1        -- TE
    v.x -= 1        -- TE
    v.y *= 1        -- TE
    v.z /= 1        -- TE
    print(v.x)      -- No TE
    print(v.x > 5)  -- No TE
    v.x = 15        -- TE
end

increment(vector.create(1, 2, 3))

This PR also supports different read/write types:

-- Definition
declare extern type Foo with
    read Bar: number
    write Bar: string
end

-- Script
local f: Foo
local b: number = f.Bar
f.Bar = "Hello, World!"

Additionally,

  • Adds two new tests for the implemented syntax
  • Adds the LuauLValueCompoundAssignmentVisitLhs, LuauExternReadWriteAttributes and LuauTypeCheckerVectorReadOnly flags

Closes #2062

… and make `vector` properties read-only

Adds support for `read` and `write` property attributes for extern type declarations
The structure is intended to be the same as for table types:

declare extern type E as
	(read/write/<blank>) <property>: T
end

Modifies the embedded type definition of `vector`s to mark `.x`, `.y` and `.z` as read-only
My mistake!
This is after migrating to the latest version of Luau, the previous changes were actually written on the *prior* release and copied over (imperfectly) but it should all be good now
@Stupid-Noob-Scripter
Copy link

I don't know what any of these means but I think they're pretty cool
this deserves 6-7 stars

Copy link
Collaborator

@andyfriesen andyfriesen left a comment

Choose a reason for hiding this comment

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

Thanks for the patch!

This all looks fine. We just need you to flag it before we can merge it.

PhoenixWhitefire and others added 5 commits November 19, 2025 05:23
In order to maintain the `LuauTypeCheckerVectorLerp2` flag, I would have to add 2 extra copies of the `vector` library definitions.
`vector.lerp` has been out for several months now anyway, the rest of the rollout flags should also probably be removed...
Now, it only affects the fastcall guard
@PhoenixWhitefire
Copy link
Contributor Author

PhoenixWhitefire commented Nov 19, 2025

The flags LuauExternReadWriteAttributes and LuauTypeCheckerVectorReadOnly have been added
LuauTypeCheckerVectorLerp2 has been removed to prevent there being too many different combinations of the embedded vector definition
LuauVectorLerp no longer has any effect on the VM outside of allowing fastcalls. It felt better to do this than patch the failing test complaining about it not existing despite being defined in the type system due to the above flag removal (maybe the rest of the lerp rollout flags could also be removed, but that felt even further outside the scope of this PR and I didn't want to bring too many different areas into this)

@andyfriesen andyfriesen self-assigned this Nov 26, 2025
@PhoenixWhitefire PhoenixWhitefire marked this pull request as draft November 30, 2025 18:23
@PhoenixWhitefire PhoenixWhitefire marked this pull request as ready for review December 1, 2025 07:26
PhoenixWhitefire and others added 3 commits December 5, 2025 20:30
I need to fix this bug in 2 different PRs, so I'm flagging it with a non-PR-specific name
@PhoenixWhitefire
Copy link
Contributor Author

Added the flag LuauLValueCompoundAssignmentVisitLhs because I need to fix that bug in #2137 as well

@PhoenixWhitefire
Copy link
Contributor Author

LuauTypeCheckerVectorLerp2 was clipped in 703 and I only noticed today 🙃

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.

[new solver] compound assignment of vector components *does not* raise TypeError

3 participants