mirror of
https://github.com/luau-lang/luau.git
synced 2025-04-03 02:10:53 +01:00
After a very auspicious release last week, we have a new bevy of changes for you! ## What's Changed ### Deprecated Attribute This release includes an implementation of the `@deprecated` attribute proposed in [this RFC](https://rfcs.luau.org/syntax-attribute-functions-deprecated.html). It relies on the new type solver to propagate deprecation information from function and method AST nodes to the corresponding type objects. These objects are queried by a linter pass when it encounters local, global, or indexed variables, to issue deprecation warnings. Uses of deprecated functions and methods in recursion are ignored. To support deprecation of class methods, the parser has been extended to allow attribute declarations on class methods. The implementation does not support parameters, so it is not currently possible for users to customize deprecation messages. ### General - Add a limit for normalization of function types. ### New Type Solver - Fix type checker to accept numbers as concat operands (Fixes #1671). - Fix user-defined type functions failing when used inside type aliases/nested calls (Fixes #1738, Fixes #1679). - Improve constraint generation for overloaded functions (in part thanks to @vvatheus in #1694). - Improve type inference for indexers on table literals, especially when passing table literals directly as a function call argument. - Equate regular error type and intersection with a negation of an error type. - Avoid swapping types in 2-part union when RHS is optional. - Use simplification when doing `~nil` refinements. - `len<>` now works on metatables without `__len` function. ### AST - Retain source information for `AstTypeUnion` and `AstTypeIntersection`. ### Transpiler - Print attributes on functions. ### Parser - Allow types in indexers to begin with string literals by @jackdotink in #1750. ### Autocomplete - Evaluate user-defined type functions in ill-formed source code to provide autocomplete. - Fix the start location of functions that have attributes. - Implement better fragment selection. ### Internal Contributors Co-authored-by: Andy Friesen <afriesen@roblox.com> Co-authored-by: Ariel Weiss <aaronweiss@roblox.com> Co-authored-by: Aviral Goel <agoel@roblox.com> Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com> Co-authored-by: Sora Kanosue <skanosue@roblox.com> Co-authored-by: Talha Pathan <tpathan@roblox.com> Co-authored-by: Varun Saini <vsaini@roblox.com> Co-authored-by: Vighnesh Vijay <vvijay@roblox.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com> **Full Changelog**: https://github.com/luau-lang/luau/compare/0.666...0.667 --------- Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com> Co-authored-by: Varun Saini <61795485+vrn-sn@users.noreply.github.com> Co-authored-by: Menarul Alam <malam@roblox.com> Co-authored-by: Aviral Goel <agoel@roblox.com> Co-authored-by: Vighnesh <vvijay@roblox.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com> Co-authored-by: Ariel Weiss <aaronweiss@roblox.com>
268 lines
7.8 KiB
C++
268 lines
7.8 KiB
C++
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
#include "Luau/Ast.h"
|
|
#include "Luau/Cst.h"
|
|
#include "Luau/Common.h"
|
|
|
|
namespace Luau
|
|
{
|
|
|
|
int gCstRttiIndex = 0;
|
|
|
|
CstExprConstantNumber::CstExprConstantNumber(const AstArray<char>& value)
|
|
: CstNode(CstClassIndex())
|
|
, value(value)
|
|
{
|
|
}
|
|
|
|
CstExprConstantString::CstExprConstantString(AstArray<char> sourceString, QuoteStyle quoteStyle, unsigned int blockDepth)
|
|
: CstNode(CstClassIndex())
|
|
, sourceString(sourceString)
|
|
, quoteStyle(quoteStyle)
|
|
, blockDepth(blockDepth)
|
|
{
|
|
LUAU_ASSERT(blockDepth == 0 || quoteStyle == QuoteStyle::QuotedRaw);
|
|
}
|
|
|
|
CstExprCall::CstExprCall(std::optional<Position> openParens, std::optional<Position> closeParens, AstArray<Position> commaPositions)
|
|
: CstNode(CstClassIndex())
|
|
, openParens(openParens)
|
|
, closeParens(closeParens)
|
|
, commaPositions(commaPositions)
|
|
{
|
|
}
|
|
|
|
CstExprIndexExpr::CstExprIndexExpr(Position openBracketPosition, Position closeBracketPosition)
|
|
: CstNode(CstClassIndex())
|
|
, openBracketPosition(openBracketPosition)
|
|
, closeBracketPosition(closeBracketPosition)
|
|
{
|
|
}
|
|
|
|
CstExprFunction::CstExprFunction() : CstNode(CstClassIndex())
|
|
{
|
|
}
|
|
|
|
CstExprTable::CstExprTable(const AstArray<Item>& items)
|
|
: CstNode(CstClassIndex())
|
|
, items(items)
|
|
{
|
|
}
|
|
|
|
CstExprOp::CstExprOp(Position opPosition)
|
|
: CstNode(CstClassIndex())
|
|
, opPosition(opPosition)
|
|
{
|
|
}
|
|
|
|
CstExprTypeAssertion::CstExprTypeAssertion(Position opPosition)
|
|
: CstNode(CstClassIndex())
|
|
, opPosition(opPosition)
|
|
{
|
|
}
|
|
|
|
CstExprIfElse::CstExprIfElse(Position thenPosition, Position elsePosition, bool isElseIf)
|
|
: CstNode(CstClassIndex())
|
|
, thenPosition(thenPosition)
|
|
, elsePosition(elsePosition)
|
|
, isElseIf(isElseIf)
|
|
{
|
|
}
|
|
|
|
CstExprInterpString::CstExprInterpString(AstArray<AstArray<char>> sourceStrings, AstArray<Position> stringPositions)
|
|
: CstNode(CstClassIndex())
|
|
, sourceStrings(sourceStrings)
|
|
, stringPositions(stringPositions)
|
|
{
|
|
}
|
|
|
|
CstStatDo::CstStatDo(Position endPosition)
|
|
: CstNode(CstClassIndex())
|
|
, endPosition(endPosition)
|
|
{
|
|
}
|
|
|
|
CstStatRepeat::CstStatRepeat(Position untilPosition)
|
|
: CstNode(CstClassIndex())
|
|
, untilPosition(untilPosition)
|
|
{
|
|
}
|
|
|
|
CstStatReturn::CstStatReturn(AstArray<Position> commaPositions)
|
|
: CstNode(CstClassIndex())
|
|
, commaPositions(commaPositions)
|
|
{
|
|
}
|
|
|
|
CstStatLocal::CstStatLocal(AstArray<Position> varsCommaPositions, AstArray<Position> valuesCommaPositions)
|
|
: CstNode(CstClassIndex())
|
|
, varsCommaPositions(varsCommaPositions)
|
|
, valuesCommaPositions(valuesCommaPositions)
|
|
{
|
|
}
|
|
|
|
CstStatFor::CstStatFor(Position equalsPosition, Position endCommaPosition, std::optional<Position> stepCommaPosition)
|
|
: CstNode(CstClassIndex())
|
|
, equalsPosition(equalsPosition)
|
|
, endCommaPosition(endCommaPosition)
|
|
, stepCommaPosition(stepCommaPosition)
|
|
{
|
|
}
|
|
|
|
CstStatForIn::CstStatForIn(AstArray<Position> varsCommaPositions, AstArray<Position> valuesCommaPositions)
|
|
: CstNode(CstClassIndex())
|
|
, varsCommaPositions(varsCommaPositions)
|
|
, valuesCommaPositions(valuesCommaPositions)
|
|
{
|
|
}
|
|
|
|
CstStatAssign::CstStatAssign(AstArray<Position> varsCommaPositions, Position equalsPosition, AstArray<Position> valuesCommaPositions)
|
|
: CstNode(CstClassIndex())
|
|
, varsCommaPositions(varsCommaPositions)
|
|
, equalsPosition(equalsPosition)
|
|
, valuesCommaPositions(valuesCommaPositions)
|
|
{
|
|
}
|
|
|
|
CstStatCompoundAssign::CstStatCompoundAssign(Position opPosition)
|
|
: CstNode(CstClassIndex())
|
|
, opPosition(opPosition)
|
|
{
|
|
}
|
|
|
|
CstStatFunction::CstStatFunction(Position functionKeywordPosition)
|
|
: CstNode(CstClassIndex())
|
|
, functionKeywordPosition(functionKeywordPosition)
|
|
{
|
|
}
|
|
|
|
CstStatLocalFunction::CstStatLocalFunction(Position localKeywordPosition, Position functionKeywordPosition)
|
|
: CstNode(CstClassIndex())
|
|
, localKeywordPosition(localKeywordPosition)
|
|
, functionKeywordPosition(functionKeywordPosition)
|
|
{
|
|
}
|
|
|
|
CstGenericType::CstGenericType(std::optional<Position> defaultEqualsPosition)
|
|
: CstNode(CstClassIndex())
|
|
, defaultEqualsPosition(defaultEqualsPosition)
|
|
{
|
|
}
|
|
|
|
CstGenericTypePack::CstGenericTypePack(Position ellipsisPosition, std::optional<Position> defaultEqualsPosition)
|
|
: CstNode(CstClassIndex())
|
|
, ellipsisPosition(ellipsisPosition)
|
|
, defaultEqualsPosition(defaultEqualsPosition)
|
|
{
|
|
}
|
|
|
|
CstStatTypeAlias::CstStatTypeAlias(
|
|
Position typeKeywordPosition,
|
|
Position genericsOpenPosition,
|
|
AstArray<Position> genericsCommaPositions,
|
|
Position genericsClosePosition,
|
|
Position equalsPosition
|
|
)
|
|
: CstNode(CstClassIndex())
|
|
, typeKeywordPosition(typeKeywordPosition)
|
|
, genericsOpenPosition(genericsOpenPosition)
|
|
, genericsCommaPositions(genericsCommaPositions)
|
|
, genericsClosePosition(genericsClosePosition)
|
|
, equalsPosition(equalsPosition)
|
|
{
|
|
}
|
|
|
|
CstStatTypeFunction::CstStatTypeFunction(Position typeKeywordPosition, Position functionKeywordPosition)
|
|
: CstNode(CstClassIndex())
|
|
, typeKeywordPosition(typeKeywordPosition)
|
|
, functionKeywordPosition(functionKeywordPosition)
|
|
{
|
|
}
|
|
|
|
CstTypeReference::CstTypeReference(
|
|
std::optional<Position> prefixPointPosition,
|
|
Position openParametersPosition,
|
|
AstArray<Position> parametersCommaPositions,
|
|
Position closeParametersPosition
|
|
)
|
|
: CstNode(CstClassIndex())
|
|
, prefixPointPosition(prefixPointPosition)
|
|
, openParametersPosition(openParametersPosition)
|
|
, parametersCommaPositions(parametersCommaPositions)
|
|
, closeParametersPosition(closeParametersPosition)
|
|
{
|
|
}
|
|
|
|
CstTypeTable::CstTypeTable(AstArray<Item> items, bool isArray)
|
|
: CstNode(CstClassIndex())
|
|
, items(items)
|
|
, isArray(isArray)
|
|
{
|
|
}
|
|
|
|
CstTypeFunction::CstTypeFunction(
|
|
Position openGenericsPosition,
|
|
AstArray<Position> genericsCommaPositions,
|
|
Position closeGenericsPosition,
|
|
Position openArgsPosition,
|
|
AstArray<std::optional<Position>> argumentNameColonPositions,
|
|
AstArray<Position> argumentsCommaPositions,
|
|
Position closeArgsPosition,
|
|
Position returnArrowPosition
|
|
)
|
|
: CstNode(CstClassIndex())
|
|
, openGenericsPosition(openGenericsPosition)
|
|
, genericsCommaPositions(genericsCommaPositions)
|
|
, closeGenericsPosition(closeGenericsPosition)
|
|
, openArgsPosition(openArgsPosition)
|
|
, argumentNameColonPositions(argumentNameColonPositions)
|
|
, argumentsCommaPositions(argumentsCommaPositions)
|
|
, closeArgsPosition(closeArgsPosition)
|
|
, returnArrowPosition(returnArrowPosition)
|
|
{
|
|
}
|
|
|
|
CstTypeTypeof::CstTypeTypeof(Position openPosition, Position closePosition)
|
|
: CstNode(CstClassIndex())
|
|
, openPosition(openPosition)
|
|
, closePosition(closePosition)
|
|
{
|
|
}
|
|
|
|
CstTypeUnion::CstTypeUnion(std::optional<Position> leadingPosition, AstArray<Position> separatorPositions)
|
|
: CstNode(CstClassIndex())
|
|
, leadingPosition(leadingPosition)
|
|
, separatorPositions(separatorPositions)
|
|
{
|
|
}
|
|
|
|
CstTypeIntersection::CstTypeIntersection(std::optional<Position> leadingPosition, AstArray<Position> separatorPositions)
|
|
: CstNode(CstClassIndex())
|
|
, leadingPosition(leadingPosition)
|
|
, separatorPositions(separatorPositions)
|
|
{
|
|
}
|
|
|
|
CstTypeSingletonString::CstTypeSingletonString(AstArray<char> sourceString, CstExprConstantString::QuoteStyle quoteStyle, unsigned int blockDepth)
|
|
: CstNode(CstClassIndex())
|
|
, sourceString(sourceString)
|
|
, quoteStyle(quoteStyle)
|
|
, blockDepth(blockDepth)
|
|
{
|
|
LUAU_ASSERT(quoteStyle != CstExprConstantString::QuotedInterp);
|
|
}
|
|
|
|
CstTypePackExplicit::CstTypePackExplicit(Position openParenthesesPosition, Position closeParenthesesPosition, AstArray<Position> commaPositions)
|
|
: CstNode(CstClassIndex())
|
|
, openParenthesesPosition(openParenthesesPosition)
|
|
, closeParenthesesPosition(closeParenthesesPosition)
|
|
, commaPositions(commaPositions)
|
|
{
|
|
}
|
|
|
|
CstTypePackGeneric::CstTypePackGeneric(Position ellipsisPosition)
|
|
: CstNode(CstClassIndex())
|
|
, ellipsisPosition(ellipsisPosition)
|
|
{
|
|
}
|
|
|
|
} // namespace Luau
|