-
Notifications
You must be signed in to change notification settings - Fork 11
Mark the functions that have a magic type #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7dd44de
51958a6
1598702
ebc6030
af0f863
fcfc4ea
141801a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -230,27 +230,27 @@ export type PrimParamsSetterType = typeof( | |
| ) | ||
|
|
||
|
|
||
| declare function assert<T>(value: T?, errorMessage: string?): T | ||
| -- declare function assert<T>(value: T?, errorMessage: string?): T -- magic type | ||
| declare function dangerouslyexecuterequiredmodule(f: (...any) -> ...any): ...any | ||
| declare function error<T>(message: T, level: number?): never | ||
| declare function gcinfo(): number | ||
| declare getfenv: nil | ||
| declare function getmetatable<T>(obj: T): getmetatable<T> | ||
| -- declare function getmetatable<T>(obj: T): getmetatable<T> -- builtin | ||
| declare function ipairs<V>(tab: {V}): (({V}, number) -> (number?, V), {V}, number) | ||
| declare loadstring: nil | ||
| declare function newproxy(mt: boolean?): any | ||
| declare function next<K, V>(t: {[K]: V}, i: K?): (K?, V) | ||
| declare function pairs<K, V>(t: {[K]: V}): (({[K]: V}, K?) -> (K?, V), {[K]: V}, K) | ||
| -- declare function next<K, V>(t: {[K]: V}, i: K?): (K?, V) -- builtin | ||
| -- declare function pairs<K, V>(t: {[K]: V}): (({[K]: V}, K?) -> (K?, V), {[K]: V}, K) -- builtin | ||
| declare function pcall<A..., R...>(f: (A...) -> R..., ...: A...): (boolean, R...) | ||
| declare function print<T...>(...: T...): () | ||
| declare function rawequal<T1, T2>(a: T1, b: T2): boolean | ||
| declare function rawget<K, V>(t: {[K]: V}, k: K): V? | ||
| declare function rawlen<K, V>(t: {[K]: V} | string): number | ||
| declare function rawset<K, V>(t: {[K]: V}, k: K, v: V): {[K]: V} | ||
| declare function require(target: any): any | ||
| declare function select<A...>(i: string | number, ...: A...): ...any | ||
| -- declare function require(target: any): any -- magic type | ||
| -- declare function select<A...>(i: string | number, ...: A...): ...any -- magic type | ||
| declare setfenv: nil | ||
| declare function setmetatable<T, MT>(t: T, mt: MT): setmetatable<T, MT> | ||
| -- declare function setmetatable<T, MT>(t: T, mt: MT): setmetatable<T, MT> -- builtin, magic type | ||
| declare function tonumber(value: string? | number, base: number?): number? | ||
| declare function toquaternion(value: string? | quaternion): quaternion? | ||
| declare function torotation(value: string? | quaternion): quaternion? | ||
|
|
@@ -466,31 +466,33 @@ declare quaternion: ((x: number, y: number, z: number, s: number) -> quaternion) | |
| toup: (q: quaternion) -> vector, | ||
| } | ||
|
|
||
| --[[ commented out to avoid shadowing magic type functions find, format, gmatch, and match | ||
|
|
||
| --------------------------- | ||
| -- Global Table: string | ||
| --------------------------- | ||
|
|
||
| declare string: { | ||
| byte: (s: string, i: number?, j: number?) -> ...number, | ||
| char: (...number) -> string, | ||
| find: (s: string, pattern: string, init: number?, plain: boolean?) -> (number?, number?, ...string), | ||
| format: (formatstring: string, ...any) -> string, | ||
| gmatch: (s: string, pattern: string) -> () -> ...string, | ||
| gsub: (s: string, pattern: string, repl: string | { [string]: string } | (...string) -> string, maxn: number?) -> (string, number), | ||
| len: (s: string) -> number, | ||
| lower: (s: string) -> string, | ||
| match: (s: string, pattern: string, init: number?) -> ...string, | ||
| pack: (fmt: string, ...any) -> string, | ||
| packsize: (fmt: string) -> number, | ||
| rep: (s: string, n: number) -> string, | ||
| reverse: (s: string) -> string, | ||
| split: (s: string, separator: string?) -> {string}, | ||
| sub: (s: string, i: number, j: number?) -> string, | ||
| unpack: (fmt: string, s: string, init: number?) -> ...any, | ||
| upper: (s: string) -> string, | ||
| byte: (s: string, i: number?, j: number?) -> ...number, -- builtin | ||
| char: (...number) -> string, -- builtin | ||
| find: (s: string, pattern: string, init: number?, plain: boolean?) -> (number?, number?, ...string), -- builtin, magic type | ||
| format: (formatstring: string, ...any) -> string, -- builtin, magic type | ||
| gmatch: (s: string, pattern: string) -> () -> ...string, -- builtin, magic type | ||
| gsub: (s: string, pattern: string, repl: string | { [string]: string } | (...string) -> string, maxn: number?) -> (string, number), -- builtin | ||
| len: (s: string) -> number, -- builtin | ||
| lower: (s: string) -> string, -- builtin | ||
| match: (s: string, pattern: string, init: number?) -> ...string, -- builtin, magic type | ||
| pack: (fmt: string, ...any) -> string, -- builtin | ||
| packsize: (fmt: string) -> number, -- builtin | ||
| rep: (s: string, n: number) -> string, -- builtin | ||
| reverse: (s: string) -> string, -- builtin | ||
| split: (s: string, separator: string?) -> {string}, -- builtin | ||
| sub: (s: string, i: number, j: number?) -> string, -- builtin | ||
| unpack: (fmt: string, s: string, init: number?) -> ...any, -- builtin | ||
| upper: (s: string) -> string, -- builtin | ||
| } | ||
|
|
||
| --]] | ||
|
|
||
| --------------------------- | ||
| -- Global Table: table | ||
|
|
@@ -508,16 +510,16 @@ declare table: { | |
| extend: <V>(a: {V}, b: {V}) -> {V}, | ||
| remove: <V>(a: {V}, i: number?) -> V?, | ||
| sort: <V>(a: {V}, f: ((a: V, b: V) -> boolean)?) -> (), | ||
| pack: <V>(...V) -> { n: number, [number]: V }, | ||
| pack: <V>(...V) -> { n: number, [number]: V }, -- magic type | ||
| unpack: <V>(a: {V}, i: number?, j: number?) -> ...V, | ||
| move: <V>(src: {V}, i: number, j: number, d: number, dest: {V}?) -> {V}, | ||
| create: <V>(n: number, v: V?) -> {V}, | ||
| find: <V>(t: {V}, v: V, i: number?) -> number?, | ||
| clear: (t: {}) -> (), | ||
| shrink: <V>(t: {V}, shrink_sparse: boolean?) -> {V}, | ||
| freeze: <table>(t: table) -> table, | ||
| freeze: <table>(t: table) -> table, -- magic type | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. --!strict
type objTable = {x: string}
type hashTable = {[string]: string}
local o: objTable = {x="yo"}
local _o: objTable = table.freeze(o)
_o.x = "error"
local h: hashTable = {x="yo"}
local _h: hashTable = table.freeze(h)
_h.x = "error"
local _n: number = table.freeze(5)Magic knows that Without magic, "generic table" is an unexpressable type and the file must resort to "generic anything" Neither one understands the real purpose of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Luau 0.720 improved the --!strict
type objTable = {x: string}
local o: objTable = {x="yo"}
local of = table.freeze(o)
of.x = "error"Magic now knows the table is read-only (new solver only): Without magic, or in the old solver, table writing is not detected as an error: |
||
| isfrozen: (t: {}) -> boolean, | ||
| clone: <table>(t: table) -> table, | ||
| clone: <table>(t: table) -> table, -- magic type | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. --!strict
type objTable = {x: string}
type hashTable = {[string]: string}
local o: objTable = {x="yo"}
local _o: objTable = table.clone(o)
local h: hashTable = {x="yo"}
local _h: hashTable = table.clone(h)
local _n: number = table.clone(5)Magic knows that Without magic, "generic table" is an unexpressable type and the file must resort to "generic anything"
|
||
| } | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magic knows to union all the
table.packparameters for the return type:Without magic, this is not supported by the type system: