From 13f04344917213c0ba20ea93ee781676c7979822 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Thu, 8 Sep 2022 12:58:01 +0200 Subject: [PATCH 01/26] bump to 1.20.0 --- build.gradle.kts | 2 +- changelog/1.20.0.md | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 changelog/1.20.0.md diff --git a/build.gradle.kts b/build.gradle.kts index e6cb40c78..c84f0becb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,7 +15,7 @@ fun prop(name: String): String = val kotlinVersion = "1.7.10" val pluginJarName = "intellij-move-$shortPlatformVersion" -val pluginVersion = "1.19.0" +val pluginVersion = "1.20.0" val pluginGroup = "org.move" group = pluginGroup diff --git a/changelog/1.20.0.md b/changelog/1.20.0.md new file mode 100644 index 000000000..c949e8c32 --- /dev/null +++ b/changelog/1.20.0.md @@ -0,0 +1,11 @@ +# INTELLIJ MOVE CHANGELOG: 1.20.0 + +TBD + +## New Features + +## Fixes + +* Allow spaces inside `public(friend)` function modifier. + +## Internal From 642b6ca7482adb1f4ce1bd01d3c52717fb57ccab Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Thu, 8 Sep 2022 12:58:18 +0200 Subject: [PATCH 02/26] remove traces of Rust --- .../move/lang/core/completion/sort/MvCompletionWeighers.kt | 2 +- src/main/kotlin/org/move/openapiext/CommandLineExt.kt | 2 +- src/main/kotlin/org/move/utils/AsyncParameterInfoHandler.kt | 2 +- src/main/kotlin/org/move/utils/tests/MvTestBase.kt | 4 ++-- .../org/move/ide/inspections/MvTypeCheckInspectionTest.kt | 1 + 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/org/move/lang/core/completion/sort/MvCompletionWeighers.kt b/src/main/kotlin/org/move/lang/core/completion/sort/MvCompletionWeighers.kt index 99fb4f82e..f87e1b598 100644 --- a/src/main/kotlin/org/move/lang/core/completion/sort/MvCompletionWeighers.kt +++ b/src/main/kotlin/org/move/lang/core/completion/sort/MvCompletionWeighers.kt @@ -73,7 +73,7 @@ private val COMPLETION_WEIGHERS: List = listOf( */ "priority", - preferTrue(P::isReturnTypeConformsToExpectedType, id = "rust-prefer-matching-expected-type"), + preferTrue(P::isReturnTypeConformsToExpectedType, id = "move-prefer-matching-expected-type"), // preferTrue(P::typeHasAllRequiredAbilities, id = "rust-prefer-matching-abilities"), // preferTrue(P::isCompatibleWithContext, id = "rust-prefer-matching-context"), diff --git a/src/main/kotlin/org/move/openapiext/CommandLineExt.kt b/src/main/kotlin/org/move/openapiext/CommandLineExt.kt index 6f496c3b7..05cf981f0 100644 --- a/src/main/kotlin/org/move/openapiext/CommandLineExt.kt +++ b/src/main/kotlin/org/move/openapiext/CommandLineExt.kt @@ -21,7 +21,7 @@ import org.move.stdext.MvResult import org.move.stdext.unwrapOrElse import java.nio.file.Path -private val LOG = Logger.getInstance("org.rust.openapiext.CommandLineExt") +private val LOG = Logger.getInstance("org.move.openapiext.CommandLineExt") //@Suppress("FunctionName") //fun GeneralCommandLine(path: Path, vararg args: String) = diff --git a/src/main/kotlin/org/move/utils/AsyncParameterInfoHandler.kt b/src/main/kotlin/org/move/utils/AsyncParameterInfoHandler.kt index 5d61b1ba0..d5e594c64 100644 --- a/src/main/kotlin/org/move/utils/AsyncParameterInfoHandler.kt +++ b/src/main/kotlin/org/move/utils/AsyncParameterInfoHandler.kt @@ -60,6 +60,6 @@ abstract class AsyncParameterInfoHandler Date: Sat, 10 Sep 2022 12:28:46 +0200 Subject: [PATCH 03/26] highlight hex integer literals --- changelog/1.20.0.md | 4 ++++ .../org/move/ide/annotator/HighlightingAnnotator.kt | 7 +++++-- .../org/move/ide/annotator/HighlightingAnnotatorTest.kt | 9 +++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/changelog/1.20.0.md b/changelog/1.20.0.md index c949e8c32..9023d924b 100644 --- a/changelog/1.20.0.md +++ b/changelog/1.20.0.md @@ -4,6 +4,10 @@ TBD ## New Features +* Highlight hex integer literals + +TODO: screenshot + ## Fixes * Allow spaces inside `public(friend)` function modifier. diff --git a/src/main/kotlin/org/move/ide/annotator/HighlightingAnnotator.kt b/src/main/kotlin/org/move/ide/annotator/HighlightingAnnotator.kt index 966be8dcb..858356df6 100644 --- a/src/main/kotlin/org/move/ide/annotator/HighlightingAnnotator.kt +++ b/src/main/kotlin/org/move/ide/annotator/HighlightingAnnotator.kt @@ -4,6 +4,7 @@ import com.intellij.lang.annotation.AnnotationHolder import com.intellij.psi.PsiElement import com.intellij.psi.impl.source.tree.LeafPsiElement import org.move.ide.colors.MvColor +import org.move.lang.MvElementTypes.HEX_INTEGER_LITERAL import org.move.lang.MvElementTypes.IDENTIFIER import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.* @@ -38,9 +39,11 @@ class HighlightingAnnotator : MvAnnotator() { private fun highlightLeaf(element: PsiElement): MvColor? { val parent = element.parent as? MvElement ?: return null - if (element.elementType.toString().endsWith("_kw")) return MvColor.KEYWORD + val leafType = element.elementType + if (leafType.toString().endsWith("_kw")) return MvColor.KEYWORD return when { - element.elementType == IDENTIFIER -> highlightIdentifier(parent) + leafType == IDENTIFIER -> highlightIdentifier(parent) + leafType == HEX_INTEGER_LITERAL -> MvColor.NUMBER parent is MvCopyExpr && element.text == "copy" -> MvColor.KEYWORD else -> null diff --git a/src/test/kotlin/org/move/ide/annotator/HighlightingAnnotatorTest.kt b/src/test/kotlin/org/move/ide/annotator/HighlightingAnnotatorTest.kt index f3bd0e888..a3ebefc4d 100644 --- a/src/test/kotlin/org/move/ide/annotator/HighlightingAnnotatorTest.kt +++ b/src/test/kotlin/org/move/ide/annotator/HighlightingAnnotatorTest.kt @@ -166,4 +166,13 @@ class HighlightingAnnotatorTest : AnnotatorTestCase(HighlightingAnnotator::class } } """) + + fun `test integer highlighting`() = checkHighlighting(""" + module 0x1::main { + fun main() { + let a = 0x123456; + + } + } + """) } From ae09486044b26597397270ea5a503a430ef2c147 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Sun, 11 Sep 2022 13:26:26 +0200 Subject: [PATCH 04/26] correctly infer expected type for borrow expr --- changelog/1.20.0.md | 2 + src/main/grammars/MoveParser.bnf | 14 +- .../org/move/ide/annotator/ErrorAnnotator.kt | 15 +- .../org/move/ide/formatter/impl/alignment.kt | 2 +- .../org/move/ide/formatter/impl/spacing.kt | 4 +- .../org/move/ide/formatter/impl/utils.kt | 2 +- .../ide/hints/FunctionParameterInfoHandler.kt | 12 +- .../org/move/ide/hints/InlayParameterHints.kt | 5 +- .../hints/StructLiteralFieldsInfoHandler.kt | 4 +- .../ide/inspections/MvTypeCheckInspection.kt | 13 +- .../move/ide/intentions/ChopListIntention.kt | 4 +- .../org/move/lang/core/MoveParserUtil.kt | 1 + .../org/move/lang/core/psi/ext/MoveExpr.kt | 4 +- .../org/move/lang/core/psi/ext/MovePath.kt | 2 +- .../org/move/lang/core/psi/ext/MvCallExpr.kt | 7 +- .../lang/core/types/infer/ExpectedType.kt | 17 +- .../move/lang/core/types/infer/Expressions.kt | 4 +- .../utils/tests/types/TypificationTestCase.kt | 2 + .../ide/hints/ParameterInfoHandlerTest.kt | 4 +- .../org/move/lang/types/ExpectedTypeTest.kt | 22 ++ .../move/lang/parser/complete/assignments.txt | 6 +- .../lang/parser/complete/function_calls.txt | 234 ++++++++++-------- .../lang/parser/complete/let_patterns.txt | 14 +- .../org/move/lang/parser/complete/vectors.txt | 4 +- .../move/lang/parser/partial/assignments.txt | 2 +- .../lang/parser/partial/function_calls.move | 2 + .../lang/parser/partial/function_calls.txt | 97 +++++--- .../org/move/lang/parser/specs/conditions.txt | 155 ++++++------ .../move/lang/parser/specs/forall_exists.txt | 34 +-- .../org/move/lang/parser/specs/spec_file.txt | 17 +- .../lang/parser/specs/spec_statements.txt | 147 +++++------ 31 files changed, 487 insertions(+), 365 deletions(-) diff --git a/changelog/1.20.0.md b/changelog/1.20.0.md index 9023d924b..6fdfddf41 100644 --- a/changelog/1.20.0.md +++ b/changelog/1.20.0.md @@ -8,6 +8,8 @@ TBD TODO: screenshot +* Type-driven smart completion for borrow exprs. + ## Fixes * Allow spaces inside `public(friend)` function modifier. diff --git a/src/main/grammars/MoveParser.bnf b/src/main/grammars/MoveParser.bnf index d7690470f..c02082b3a 100644 --- a/src/main/grammars/MoveParser.bnf +++ b/src/main/grammars/MoveParser.bnf @@ -864,13 +864,15 @@ LitExpr ::= HEX_INTEGER_LITERAL | AddressLit AddressLit ::= '@' AddressRef { pin = 1 } -CallExpr ::= (Path &'(') CallArgumentList { pin = 1 } -CallArgumentList ::= '(' CallArgumentList_items? ')' { pin = 1 } -private CallArgumentList_items ::= <> +CallExpr ::= (Path &'(') ValueArgumentList { pin = 1 } +ValueArgumentList ::= '(' ValueArgumentList_items? ')' { pin = 1 } +private ValueArgumentList_items ::= <> { - recoverWhile = CallArgumentList_items_recovery + recoverWhile = ValueArgumentList_items_recovery } -private CallArgumentList_items_recovery ::= !(')' | ';') +private ValueArgumentList_items_recovery ::= !(';' | ')') + +ValueArgument ::= Expr IfExpr ::= if Condition AnyBlock ElseBlock? { pin = 1 } @@ -960,7 +962,7 @@ NamedAddress ::= IDENTIFIER } /// Macros -MacroCallExpr ::= MacroIdent CallArgumentList { pin = 1 } +MacroCallExpr ::= MacroIdent ValueArgumentList { pin = 1 } MacroIdent ::= IDENTIFIER '!' /////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/main/kotlin/org/move/ide/annotator/ErrorAnnotator.kt b/src/main/kotlin/org/move/ide/annotator/ErrorAnnotator.kt index bbf4ecae2..f68da49d6 100644 --- a/src/main/kotlin/org/move/ide/annotator/ErrorAnnotator.kt +++ b/src/main/kotlin/org/move/ide/annotator/ErrorAnnotator.kt @@ -125,12 +125,12 @@ class ErrorAnnotator : MvAnnotator() { } } - override fun visitCallArgumentList(arguments: MvCallArgumentList) { + override fun visitValueArgumentList(arguments: MvValueArgumentList) { val callExpr = arguments.parent as? MvCallExpr ?: return val function = callExpr.path.reference?.resolve() as? MvFunction ?: return val expectedCount = function.parameters.size - val realCount = arguments.exprList.size + val realCount = arguments.valueArgumentList.size val errorMessage = "This function takes $expectedCount ${ pluralise( @@ -150,11 +150,12 @@ class ErrorAnnotator : MvAnnotator() { return } realCount > expectedCount -> { - arguments.exprList.drop(expectedCount).forEach { - holder.newAnnotation(HighlightSeverity.ERROR, errorMessage) - .range(it) - .create() - } + arguments.valueArgumentList.drop(expectedCount) + .forEach { + holder.newAnnotation(HighlightSeverity.ERROR, errorMessage) + .range(it) + .create() + } return } } diff --git a/src/main/kotlin/org/move/ide/formatter/impl/alignment.kt b/src/main/kotlin/org/move/ide/formatter/impl/alignment.kt index 419821291..2ba384ab3 100644 --- a/src/main/kotlin/org/move/ide/formatter/impl/alignment.kt +++ b/src/main/kotlin/org/move/ide/formatter/impl/alignment.kt @@ -5,7 +5,7 @@ import org.move.ide.formatter.MvFormatterBlock import org.move.lang.MvElementTypes.* fun MvFormatterBlock.getAlignmentStrategy(): MvAlignmentStrategy = when (node.elementType) { - FUNCTION_PARAMETER_LIST, CALL_ARGUMENT_LIST -> + FUNCTION_PARAMETER_LIST, VALUE_ARGUMENT_LIST -> MvAlignmentStrategy .shared() .alignUnlessBlockDelim() diff --git a/src/main/kotlin/org/move/ide/formatter/impl/spacing.kt b/src/main/kotlin/org/move/ide/formatter/impl/spacing.kt index 4080fef51..3bdf36b71 100644 --- a/src/main/kotlin/org/move/ide/formatter/impl/spacing.kt +++ b/src/main/kotlin/org/move/ide/formatter/impl/spacing.kt @@ -67,7 +67,7 @@ fun createSpacingBuilder(commonSettings: CommonCodeStyleSettings): SpacingBuilde .between(FUNCTION_PARAMETER_LIST, RETURN_TYPE).spaceIf(false) .between(IDENTIFIER, FUNCTION_PARAMETER_LIST).spaceIf(false) - .between(IDENTIFIER, CALL_ARGUMENT_LIST).spaceIf(false) + .between(IDENTIFIER, VALUE_ARGUMENT_LIST).spaceIf(false) .between(IDENTIFIER, TYPE_PARAMETER_LIST).spaceIf(false) .between(IDENTIFIER, TYPE_ARGUMENT_LIST).spaceIf(false) @@ -75,7 +75,7 @@ fun createSpacingBuilder(commonSettings: CommonCodeStyleSettings): SpacingBuilde // .between(IDENTIFIER, STRUCT_LIT_FIELDS_BLOCK).spaceIf(true) .between(TYPE_PARAMETER_LIST, FUNCTION_PARAMETER_LIST).spaceIf(false) - .before(CALL_ARGUMENT_LIST).spaceIf(false) + .before(VALUE_ARGUMENT_LIST).spaceIf(false) .betweenInside(PUBLIC, L_PAREN, FUNCTION_VISIBILITY_MODIFIER).spaces(0) .betweenInside( diff --git a/src/main/kotlin/org/move/ide/formatter/impl/utils.kt b/src/main/kotlin/org/move/ide/formatter/impl/utils.kt index 41fc85ae8..bf9c6b56a 100644 --- a/src/main/kotlin/org/move/ide/formatter/impl/utils.kt +++ b/src/main/kotlin/org/move/ide/formatter/impl/utils.kt @@ -19,7 +19,7 @@ val ONE_LINE_ITEMS = ts(USE_STMT, CONST) val PAREN_DELIMITED_BLOCKS = ts( PARENS_EXPR, TUPLE_PAT, TUPLE_TYPE, TUPLE_LIT_EXPR, CONDITION, - FUNCTION_PARAMETER_LIST, CALL_ARGUMENT_LIST, ATTR_ITEM_ARGUMENTS + FUNCTION_PARAMETER_LIST, VALUE_ARGUMENT_LIST, ATTR_ITEM_ARGUMENTS ) val ANGLE_DELIMITED_BLOCKS = ts(TYPE_PARAMETER_LIST, TYPE_ARGUMENT_LIST) val BRACKET_DELIMITED_BLOCKS = ts(VECTOR_LIT_ITEMS) diff --git a/src/main/kotlin/org/move/ide/hints/FunctionParameterInfoHandler.kt b/src/main/kotlin/org/move/ide/hints/FunctionParameterInfoHandler.kt index f0537010e..5cf77afae 100644 --- a/src/main/kotlin/org/move/ide/hints/FunctionParameterInfoHandler.kt +++ b/src/main/kotlin/org/move/ide/hints/FunctionParameterInfoHandler.kt @@ -7,16 +7,16 @@ import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiFile import org.move.ide.utils.CallInfo import org.move.lang.MvElementTypes -import org.move.lang.core.psi.MvCallArgumentList +import org.move.lang.core.psi.MvValueArgumentList import org.move.lang.core.psi.MvCallExpr import org.move.lang.core.psi.MvStructLitFieldsBlock import org.move.lang.core.psi.ext.ancestorOrSelf import org.move.lang.core.psi.ext.startOffset import org.move.utils.AsyncParameterInfoHandler -class FunctionParameterInfoHandler : AsyncParameterInfoHandler() { +class FunctionParameterInfoHandler : AsyncParameterInfoHandler() { - override fun findTargetElement(file: PsiFile, offset: Int): MvCallArgumentList? { + override fun findTargetElement(file: PsiFile, offset: Int): MvValueArgumentList? { val element = file.findElementAt(offset) ?: return null // val callExpr = element.ancestorStrict() ?: return null // val block = element.ancestorStrict() @@ -25,10 +25,10 @@ class FunctionParameterInfoHandler : AsyncParameterInfoHandler? = + override fun calculateParameterInfo(element: MvValueArgumentList): Array? = ParamsDescription.findDescription(element)?.let { arrayOf(it) } - override fun updateParameterInfo(parameterOwner: MvCallArgumentList, context: UpdateParameterInfoContext) { + override fun updateParameterInfo(parameterOwner: MvValueArgumentList, context: UpdateParameterInfoContext) { if (context.parameterOwner != parameterOwner) { context.removeHint() return @@ -73,7 +73,7 @@ class ParamsDescription(val parameters: Array) { /** * Finds declaration of the func/method and creates description of its arguments */ - fun findDescription(args: MvCallArgumentList): ParamsDescription? { + fun findDescription(args: MvValueArgumentList): ParamsDescription? { val call = args.parent val callInfo = (call as? MvCallExpr)?.let { CallInfo.resolve(it) } ?: return null diff --git a/src/main/kotlin/org/move/ide/hints/InlayParameterHints.kt b/src/main/kotlin/org/move/ide/hints/InlayParameterHints.kt index 2e2898892..1cecf83c8 100644 --- a/src/main/kotlin/org/move/ide/hints/InlayParameterHints.kt +++ b/src/main/kotlin/org/move/ide/hints/InlayParameterHints.kt @@ -6,6 +6,7 @@ import org.move.ide.utils.CallInfo import org.move.lang.core.psi.MvCallExpr import org.move.lang.core.psi.MvRefExpr import org.move.lang.core.psi.MvStructLitExpr +import org.move.lang.core.psi.ext.callArgumentExprs import org.move.lang.core.psi.ext.startOffset @Suppress("UnstableApiUsage") @@ -14,11 +15,9 @@ object InlayParameterHints { if (elem !is MvCallExpr) return emptyList() val callInfo = CallInfo.resolve(elem) ?: return emptyList() - val arguments = elem.callArgumentList?.exprList ?: return emptyList() - return callInfo.parameters .map { it.name } - .zip(arguments) + .zip(elem.callArgumentExprs) // don't show argument, if just function call / variable / struct literal // .filter { (_, arg) -> arg !is MvRefExpr && arg !is MvCallExpr && arg !is MvStructLitExpr } .filter { (_, arg) -> arg !is MvRefExpr && arg !is MvStructLitExpr } diff --git a/src/main/kotlin/org/move/ide/hints/StructLiteralFieldsInfoHandler.kt b/src/main/kotlin/org/move/ide/hints/StructLiteralFieldsInfoHandler.kt index 2fd3aad9d..85e1cc1a1 100644 --- a/src/main/kotlin/org/move/ide/hints/StructLiteralFieldsInfoHandler.kt +++ b/src/main/kotlin/org/move/ide/hints/StructLiteralFieldsInfoHandler.kt @@ -8,7 +8,7 @@ import com.intellij.psi.PsiFile import com.intellij.psi.tree.IElementType import org.move.ide.presentation.fullname import org.move.lang.MvElementTypes -import org.move.lang.core.psi.MvCallArgumentList +import org.move.lang.core.psi.MvValueArgumentList import org.move.lang.core.psi.MvStructLitField import org.move.lang.core.psi.MvStructLitFieldsBlock import org.move.lang.core.psi.ext.* @@ -22,7 +22,7 @@ class StructLitFieldsInfoHandler : // val block = element.ancestorStrict() ?: return null // val callExpr = element.ancestorStrict() // if (callExpr != null && block.contains(callExpr)) return null - return element.ancestorOrSelf(stopAt = MvCallArgumentList::class.java) + return element.ancestorOrSelf(stopAt = MvValueArgumentList::class.java) } override fun calculateParameterInfo(element: MvStructLitFieldsBlock): Array? = diff --git a/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt b/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt index f17a8e5aa..49a389bdc 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt @@ -26,13 +26,6 @@ fun ProblemsHolder.registerTypeError(typeError: TypeError) { } class MvTypeCheckInspection : MvLocalInspectionTool() { - companion object { - private fun invalidReturnTypeMessage(expectedTy: Ty, actualTy: Ty): String { - return "Invalid return type: " + - "expected '${expectedTy.name()}', found '${actualTy.name()}'" - } - } - override val isSyntaxOnly: Boolean get() = true override fun buildMvVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) = @@ -81,11 +74,11 @@ class MvTypeCheckInspection : MvLocalInspectionTool() { } } - override fun visitCallArgumentList(callArgs: MvCallArgumentList) { + override fun visitValueArgumentList(callArgs: MvValueArgumentList) { val callExpr = callArgs.parent as? MvCallExpr ?: return val function = callExpr.path.reference?.resolve() as? MvFunctionLike ?: return - if (function.parameters.size != callArgs.exprList.size) return + if (function.parameters.size != callArgs.valueArgumentList.size) return val inferenceCtx = callArgs.functionInferenceCtx(callArgs.isMsl()) val callTy = inferenceCtx.callExprTypes @@ -93,7 +86,7 @@ class MvTypeCheckInspection : MvLocalInspectionTool() { inferCallExprTy(callExpr, inferenceCtx, null) as? TyFunction } ?: return - for ((i, expr) in callArgs.exprList.withIndex()) { + for ((i, expr) in callArgs.argumentExprs.withIndex()) { val parameter = function.parameters[i] val paramTy = callTy.paramTypes[i] val exprTy = expr.inferredTy() diff --git a/src/main/kotlin/org/move/ide/intentions/ChopListIntention.kt b/src/main/kotlin/org/move/ide/intentions/ChopListIntention.kt index c78171dc0..a455e083d 100644 --- a/src/main/kotlin/org/move/ide/intentions/ChopListIntention.kt +++ b/src/main/kotlin/org/move/ide/intentions/ChopListIntention.kt @@ -53,8 +53,8 @@ class ChopParameterListIntention : ChopListIntentionBase( - MvCallArgumentList::class.java, +class ChopArgumentListIntention : ChopListIntentionBase( + MvValueArgumentList::class.java, MvExpr::class.java, "Put arguments on separate lines" ) diff --git a/src/main/kotlin/org/move/lang/core/MoveParserUtil.kt b/src/main/kotlin/org/move/lang/core/MoveParserUtil.kt index 4b5e39b70..a0b624190 100644 --- a/src/main/kotlin/org/move/lang/core/MoveParserUtil.kt +++ b/src/main/kotlin/org/move/lang/core/MoveParserUtil.kt @@ -3,6 +3,7 @@ package org.move.lang.core import com.intellij.lang.PsiBuilder import com.intellij.lang.PsiBuilderUtil import com.intellij.lang.WhitespacesAndCommentsBinder +import com.intellij.lang.WhitespacesBinders import com.intellij.lang.parser.GeneratedParserUtilBase import com.intellij.openapi.util.Key import com.intellij.psi.TokenType.WHITE_SPACE diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MoveExpr.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MoveExpr.kt index 6763319ae..c5b2f4446 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MoveExpr.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MoveExpr.kt @@ -3,7 +3,7 @@ package org.move.lang.core.psi.ext import org.move.lang.core.psi.MvExpr import org.move.lang.core.types.infer.InferenceContext import org.move.lang.core.types.infer.functionInferenceCtx -import org.move.lang.core.types.infer.inferExprExpectedTy +import org.move.lang.core.types.infer.inferExpectedTy import org.move.lang.core.types.infer.inferExprTy import org.move.lang.core.types.ty.Ty @@ -18,4 +18,4 @@ fun MvExpr.inferredTy(): Ty { return inferExprTy(this, inferenceCtx) } -fun MvExpr.expectedTy(ctx: InferenceContext): Ty? = inferExprExpectedTy(this, ctx) +fun MvExpr.expectedTy(ctx: InferenceContext): Ty? = inferExpectedTy(this, ctx) diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MovePath.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MovePath.kt index 6d380c325..91eaea125 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MovePath.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MovePath.kt @@ -31,7 +31,7 @@ val MvPath.isUpdateFieldArg2: Boolean ?.let { if (it.path.textMatches("update_field")) it else null } ?.let { val expr = this.ancestorStrict() ?: return@let -1 - it.arguments.indexOf(expr) + it.callArgumentExprs.indexOf(expr) } return ind == 1 } diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvCallExpr.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvCallExpr.kt index 5de2d640e..35619a153 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvCallExpr.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvCallExpr.kt @@ -1,5 +1,6 @@ package org.move.lang.core.psi.ext +import org.move.lang.core.psi.MvValueArgumentList import org.move.lang.core.psi.MvCallExpr import org.move.lang.core.psi.MvExpr import org.move.lang.core.psi.MvTypeArgument @@ -10,7 +11,11 @@ import org.move.lang.core.types.ty.TyFunction val MvCallExpr.typeArguments: List get() = this.path.typeArguments -val MvCallExpr.arguments: List get() = this.callArgumentList?.exprList.orEmpty() +val MvCallExpr.callArgumentExprs: List + get() = this.valueArgumentList + ?.valueArgumentList.orEmpty().map { it.expr } + +val MvValueArgumentList.argumentExprs: List get() = this.valueArgumentList.map { it.expr } fun MvCallExpr.acquiresTys(ctx: InferenceContext): List = (inferCallExprTy(this, ctx, null) as? TyFunction)?.acquiresTypes.orEmpty() diff --git a/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt b/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt index 4bf69f357..afad5df1d 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt @@ -5,17 +5,23 @@ import org.move.lang.core.psi.ext.declaredTy import org.move.lang.core.psi.ext.isMsl import org.move.lang.core.psi.ext.ty import org.move.lang.core.types.ty.Ty +import org.move.lang.core.types.ty.TyReference import org.move.lang.core.types.ty.TyUnknown -fun inferExprExpectedTy(expr: MvExpr, ctx: InferenceContext): Ty? { - val owner = expr.parent +fun inferExpectedTy(element: MvElement, ctx: InferenceContext): Ty? { + val owner = element.parent return when (owner) { - is MvCallArgumentList -> { + is MvBorrowExpr -> { + val refTy = inferExpectedTy(owner, ctx) as? TyReference ?: return null + refTy.innerTy() + } + is MvValueArgument -> { + val valueArgumentList = owner.parent as MvValueArgumentList val paramIndex = - owner.children.indexOfFirst { it.textRange.contains(expr.textOffset) } + valueArgumentList.children.indexOfFirst { it.textRange.contains(owner.textOffset) } if (paramIndex == -1) return null - val callExpr = owner.parent as? MvCallExpr ?: return null + val callExpr = valueArgumentList.parent as? MvCallExpr ?: return null val inferenceCtx = callExpr.functionInferenceCtx(callExpr.isMsl()) inferenceCtx.callExprTypes[callExpr] ?.paramTypes @@ -34,7 +40,6 @@ fun inferExprExpectedTy(expr: MvExpr, ctx: InferenceContext): Ty? { } is MvStructPat -> pat.ty() else -> null -// else -> TyUnknown } } else -> null diff --git a/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt b/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt index b6c9fcbd3..b7680dcad 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt @@ -135,8 +135,8 @@ fun inferCallExprTy( } } // find all types of passed expressions, create constraints with those - if (callExpr.arguments.isNotEmpty()) { - for ((paramTy, argumentExpr) in funcTy.paramTypes.zip(callExpr.arguments)) { + if (callExpr.callArgumentExprs.isNotEmpty()) { + for ((paramTy, argumentExpr) in funcTy.paramTypes.zip(callExpr.callArgumentExprs)) { val argumentExprTy = inferExprTy(argumentExpr, parentCtx) inferenceCtx.addConstraint(paramTy, argumentExprTy) } diff --git a/src/main/kotlin/org/move/utils/tests/types/TypificationTestCase.kt b/src/main/kotlin/org/move/utils/tests/types/TypificationTestCase.kt index 76a0c8d92..49bf8c11f 100644 --- a/src/main/kotlin/org/move/utils/tests/types/TypificationTestCase.kt +++ b/src/main/kotlin/org/move/utils/tests/types/TypificationTestCase.kt @@ -2,11 +2,13 @@ package org.move.utils.tests.types import org.intellij.lang.annotations.Language import org.move.ide.presentation.text +import org.move.lang.core.psi.MvElement import org.move.lang.core.psi.MvExpr import org.move.lang.core.psi.ext.expectedTy import org.move.lang.core.psi.ext.inferredTy import org.move.lang.core.psi.ext.isMsl import org.move.lang.core.types.infer.functionInferenceCtx +import org.move.lang.core.types.infer.inferExpectedTy import org.move.utils.tests.InlineFile import org.move.utils.tests.MvTestBase import org.move.utils.tests.base.findElementAndDataInEditor diff --git a/src/test/kotlin/org/move/ide/hints/ParameterInfoHandlerTest.kt b/src/test/kotlin/org/move/ide/hints/ParameterInfoHandlerTest.kt index ce3157b78..527c31749 100644 --- a/src/test/kotlin/org/move/ide/hints/ParameterInfoHandlerTest.kt +++ b/src/test/kotlin/org/move/ide/hints/ParameterInfoHandlerTest.kt @@ -1,10 +1,10 @@ package org.move.ide.hints -import org.move.lang.core.psi.MvCallArgumentList +import org.move.lang.core.psi.MvValueArgumentList import org.move.utils.tests.ParameterInfoHandlerTestCase class ParameterInfoHandlerTest - : ParameterInfoHandlerTestCase(FunctionParameterInfoHandler()) { + : ParameterInfoHandlerTestCase(FunctionParameterInfoHandler()) { fun `test fun no args`() = checkByText(""" module M { diff --git a/src/test/kotlin/org/move/lang/types/ExpectedTypeTest.kt b/src/test/kotlin/org/move/lang/types/ExpectedTypeTest.kt index ddfb19332..5fb20bace 100644 --- a/src/test/kotlin/org/move/lang/types/ExpectedTypeTest.kt +++ b/src/test/kotlin/org/move/lang/types/ExpectedTypeTest.kt @@ -112,4 +112,26 @@ class ExpectedTypeTest : TypificationTestCase() { } """ ) + + fun `test borrow type`() = testExpectedTypeExpr(""" + module 0x1::main { + struct LiquidityPool {} + fun call(pool: &LiquidityPool) {} + fun main() { + call(&myref); + //^ 0x1::main::LiquidityPool + } + } + """) + + fun `test borrow mut type`() = testExpectedTypeExpr(""" + module 0x1::main { + struct LiquidityPool {} + fun call(pool: &mut LiquidityPool) {} + fun main() { + call(&mut myref); + //^ 0x1::main::LiquidityPool + } + } + """) } diff --git a/src/test/resources/org/move/lang/parser/complete/assignments.txt b/src/test/resources/org/move/lang/parser/complete/assignments.txt index 7d202e089..dbcb7442e 100644 --- a/src/test/resources/org/move/lang/parser/complete/assignments.txt +++ b/src/test/resources/org/move/lang/parser/complete/assignments.txt @@ -113,7 +113,7 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('call') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') PsiElement())(')') PsiElement(.)('.') @@ -134,7 +134,7 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('call') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') PsiElement())(')') PsiElement(.)('.') @@ -205,4 +205,4 @@ FILE PsiWhiteSpace('\n ') PsiElement(})('}') PsiWhiteSpace('\n') - PsiElement(})('}') \ No newline at end of file + PsiElement(})('}') diff --git a/src/test/resources/org/move/lang/parser/complete/function_calls.txt b/src/test/resources/org/move/lang/parser/complete/function_calls.txt index 299cd6ad5..9e5e5c779 100644 --- a/src/test/resources/org/move/lang/parser/complete/function_calls.txt +++ b/src/test/resources/org/move/lang/parser/complete/function_calls.txt @@ -20,7 +20,7 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('call') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') PsiElement())(')') PsiElement(;)(';') @@ -29,14 +29,16 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('call') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvLitExprImpl(LIT_EXPR) - PsiElement(INTEGER_LITERAL)('1') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(INTEGER_LITERAL)('1') PsiElement(,)(',') PsiWhiteSpace(' ') - MvLitExprImpl(LIT_EXPR) - PsiElement(INTEGER_LITERAL)('2') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(INTEGER_LITERAL)('2') PsiElement())(')') PsiElement(;)(';') PsiWhiteSpace('\n ') @@ -44,14 +46,16 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('call') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvLitExprImpl(LIT_EXPR) - PsiElement(BYTE_STRING_LITERAL)('b""') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(BYTE_STRING_LITERAL)('b""') PsiElement(,)(',') PsiWhiteSpace(' ') - MvLitExprImpl(LIT_EXPR) - PsiElement(BYTE_STRING_LITERAL)('b""') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(BYTE_STRING_LITERAL)('b""') PsiElement())(')') PsiElement(;)(';') PsiWhiteSpace('\n ') @@ -59,14 +63,16 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('call') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvLitExprImpl(LIT_EXPR) - PsiElement(BYTE_STRING_LITERAL)('b""') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(BYTE_STRING_LITERAL)('b""') PsiElement(,)(',') PsiWhiteSpace(' ') - MvLitExprImpl(LIT_EXPR) - PsiElement(HEX_STRING_LITERAL)('x""') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(HEX_STRING_LITERAL)('x""') PsiElement())(')') PsiElement(;)(';') PsiWhiteSpace('\n ') @@ -74,14 +80,16 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('call') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvLitExprImpl(LIT_EXPR) - PsiElement(HEX_STRING_LITERAL)('x""') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(HEX_STRING_LITERAL)('x""') PsiElement(,)(',') PsiWhiteSpace(' ') - MvLitExprImpl(LIT_EXPR) - PsiElement(BYTE_STRING_LITERAL)('b""') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(BYTE_STRING_LITERAL)('b""') PsiElement())(')') PsiElement(;)(';') PsiWhiteSpace('\n ') @@ -89,14 +97,16 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('call') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvLitExprImpl(LIT_EXPR) - PsiElement(HEX_STRING_LITERAL)('x""') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(HEX_STRING_LITERAL)('x""') PsiElement(,)(',') PsiWhiteSpace(' ') - MvLitExprImpl(LIT_EXPR) - PsiElement(HEX_STRING_LITERAL)('x""') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(HEX_STRING_LITERAL)('x""') PsiElement())(')') PsiElement(;)(';') PsiWhiteSpace('\n ') @@ -104,14 +114,16 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('call') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvLitExprImpl(LIT_EXPR) - PsiElement(INTEGER_LITERAL)('1') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(INTEGER_LITERAL)('1') PsiElement(,)(',') PsiWhiteSpace(' ') - MvLitExprImpl(LIT_EXPR) - PsiElement(INTEGER_LITERAL)('2') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(INTEGER_LITERAL)('2') PsiElement(,)(',') PsiElement())(')') PsiElement(;)(';') @@ -120,26 +132,31 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('call') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvLitExprImpl(LIT_EXPR) - PsiElement(INTEGER_LITERAL)('0') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(INTEGER_LITERAL)('0') PsiElement(,)(',') PsiWhiteSpace(' ') - MvLitExprImpl(LIT_EXPR) - PsiElement(INTEGER_LITERAL)('0u8') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(INTEGER_LITERAL)('0u8') PsiElement(,)(',') PsiWhiteSpace(' ') - MvLitExprImpl(LIT_EXPR) - PsiElement(INTEGER_LITERAL)('0u64') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(INTEGER_LITERAL)('0u64') PsiElement(,)(',') PsiWhiteSpace(' ') - MvLitExprImpl(LIT_EXPR) - PsiElement(INTEGER_LITERAL)('1u8') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(INTEGER_LITERAL)('1u8') PsiElement(,)(',') PsiWhiteSpace(' ') - MvLitExprImpl(LIT_EXPR) - PsiElement(INTEGER_LITERAL)('1u64') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(INTEGER_LITERAL)('1u64') PsiElement(,)(',') PsiElement())(')') PsiElement(;)(';') @@ -148,36 +165,40 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('call') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvRefExprImpl(REF_EXPR) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('a') - PsiElement(,)(',') - PsiWhiteSpace(' ') - MvDotExprImpl(DOT_EXPR) + MvValueArgumentImpl(VALUE_ARGUMENT) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('a') - PsiElement(.)('.') - MvStructDotFieldImpl(STRUCT_DOT_FIELD) - PsiElement(IDENTIFIER)('b') PsiElement(,)(',') PsiWhiteSpace(' ') - MvBorrowExprImpl(BORROW_EXPR) - PsiElement(&)('&') - MvRefExprImpl(REF_EXPR) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('a') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvDotExprImpl(DOT_EXPR) + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('a') + PsiElement(.)('.') + MvStructDotFieldImpl(STRUCT_DOT_FIELD) + PsiElement(IDENTIFIER)('b') PsiElement(,)(',') PsiWhiteSpace(' ') - MvBorrowExprImpl(BORROW_EXPR) - PsiElement(&)('&') - PsiElement(mut)('mut') - PsiWhiteSpace(' ') - MvRefExprImpl(REF_EXPR) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('a') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvBorrowExprImpl(BORROW_EXPR) + PsiElement(&)('&') + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('a') + PsiElement(,)(',') + PsiWhiteSpace(' ') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvBorrowExprImpl(BORROW_EXPR) + PsiElement(&)('&') + PsiElement(mut)('mut') + PsiWhiteSpace(' ') + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('a') PsiElement())(')') PsiElement(;)(';') PsiWhiteSpace('\n\n ') @@ -192,7 +213,7 @@ FILE MvPathImpl(PATH) PsiElement(IDENTIFIER)('u8') PsiElement(>)('>') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') PsiElement())(')') PsiElement(;)(';') @@ -214,7 +235,7 @@ FILE PsiElement(::)('::') PsiElement(IDENTIFIER)('S') PsiElement(>)('>') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') PsiElement())(')') PsiElement(;)(';') @@ -237,7 +258,7 @@ FILE PsiElement(::)('::') PsiElement(IDENTIFIER)('S') PsiElement(>)('>') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') PsiElement())(')') PsiElement(;)(';') @@ -254,7 +275,7 @@ FILE PsiElement(IDENTIFIER)('u8') PsiElement(,)(',') PsiElement(>)('>') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') PsiElement())(')') PsiElement(;)(';') @@ -283,7 +304,7 @@ FILE PsiElement(IDENTIFIER)('u8') PsiElement(>)('>') PsiElement(>)('>') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') PsiElement())(')') PsiElement(;)(';') @@ -312,31 +333,32 @@ FILE PsiElement(IDENTIFIER)('u8') PsiElement(>)('>') PsiElement(>)('>') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvCallExprImpl(CALL_EXPR) - MvPathImpl(PATH) - MvModuleRefImpl(MODULE_REF) - PsiElement(IDENTIFIER)('Transaction') - PsiElement(::)('::') - PsiElement(IDENTIFIER)('new') - MvTypeArgumentListImpl(TYPE_ARGUMENT_LIST) - PsiElement(<)('<') - MvTypeArgumentImpl(TYPE_ARGUMENT) - MvPathTypeImpl(PATH_TYPE) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('Sender') - MvTypeArgumentListImpl(TYPE_ARGUMENT_LIST) - PsiElement(<)('<') - MvTypeArgumentImpl(TYPE_ARGUMENT) - MvPathTypeImpl(PATH_TYPE) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('u8') - PsiElement(>)('>') - PsiElement(>)('>') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) - PsiElement(()('(') - PsiElement())(')') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvCallExprImpl(CALL_EXPR) + MvPathImpl(PATH) + MvModuleRefImpl(MODULE_REF) + PsiElement(IDENTIFIER)('Transaction') + PsiElement(::)('::') + PsiElement(IDENTIFIER)('new') + MvTypeArgumentListImpl(TYPE_ARGUMENT_LIST) + PsiElement(<)('<') + MvTypeArgumentImpl(TYPE_ARGUMENT) + MvPathTypeImpl(PATH_TYPE) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('Sender') + MvTypeArgumentListImpl(TYPE_ARGUMENT_LIST) + PsiElement(<)('<') + MvTypeArgumentImpl(TYPE_ARGUMENT) + MvPathTypeImpl(PATH_TYPE) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('u8') + PsiElement(>)('>') + PsiElement(>)('>') + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) + PsiElement(()('(') + PsiElement())(')') PsiElement())(')') PsiElement(;)(';') PsiWhiteSpace('\n\n ') @@ -373,7 +395,7 @@ FILE PsiElement(IDENTIFIER)('u8') PsiElement(>)('>') PsiElement(>)('>') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') PsiElement())(')') PsiElement(;)(';') @@ -382,14 +404,16 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('assert') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvLitExprImpl(LIT_EXPR) - PsiElement(BOOL_LITERAL)('true') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(BOOL_LITERAL)('true') PsiElement(,)(',') PsiWhiteSpace(' ') - MvLitExprImpl(LIT_EXPR) - PsiElement(INTEGER_LITERAL)('1') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(INTEGER_LITERAL)('1') PsiElement())(')') PsiElement(;)(';') PsiWhiteSpace('\n ') @@ -398,14 +422,16 @@ FILE MvMacroIdentImpl(MACRO_IDENT) PsiElement(IDENTIFIER)('assert') PsiElement(!)('!') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvLitExprImpl(LIT_EXPR) - PsiElement(BOOL_LITERAL)('true') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(BOOL_LITERAL)('true') PsiElement(,)(',') PsiWhiteSpace(' ') - MvLitExprImpl(LIT_EXPR) - PsiElement(INTEGER_LITERAL)('1') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(INTEGER_LITERAL)('1') PsiElement())(')') PsiElement(;)(';') PsiWhiteSpace('\n ') diff --git a/src/test/resources/org/move/lang/parser/complete/let_patterns.txt b/src/test/resources/org/move/lang/parser/complete/let_patterns.txt index 5790534fe..d2c43ac4a 100644 --- a/src/test/resources/org/move/lang/parser/complete/let_patterns.txt +++ b/src/test/resources/org/move/lang/parser/complete/let_patterns.txt @@ -83,7 +83,7 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('get_record') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') PsiElement())(')') PsiElement(;)(';') @@ -123,7 +123,7 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('get_record') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') PsiElement())(')') PsiElement(;)(';') @@ -163,7 +163,7 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('get_record') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') PsiElement())(')') PsiElement(;)(';') @@ -208,7 +208,7 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('get_record') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') PsiElement())(')') PsiElement(;)(';') @@ -261,7 +261,7 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('get_record') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') PsiElement())(')') PsiElement(;)(';') @@ -323,7 +323,7 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('get_record_tuple') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') PsiElement())(')') PsiElement(;)(';') @@ -436,4 +436,4 @@ FILE PsiWhiteSpace('\n ') PsiElement(})('}') PsiWhiteSpace('\n') - PsiElement(})('}') \ No newline at end of file + PsiElement(})('}') diff --git a/src/test/resources/org/move/lang/parser/complete/vectors.txt b/src/test/resources/org/move/lang/parser/complete/vectors.txt index fb0b4bbd9..a2b7d4d0a 100644 --- a/src/test/resources/org/move/lang/parser/complete/vectors.txt +++ b/src/test/resources/org/move/lang/parser/complete/vectors.txt @@ -121,11 +121,11 @@ FILE PsiElement(IDENTIFIER)('vector') PsiElement(::)('::') PsiElement(IDENTIFIER)('add') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') PsiElement())(')') PsiElement(;)(';') PsiWhiteSpace('\n ') PsiElement(})('}') PsiWhiteSpace('\n') - PsiElement(})('}') \ No newline at end of file + PsiElement(})('}') diff --git a/src/test/resources/org/move/lang/parser/partial/assignments.txt b/src/test/resources/org/move/lang/parser/partial/assignments.txt index a54506790..476768454 100644 --- a/src/test/resources/org/move/lang/parser/partial/assignments.txt +++ b/src/test/resources/org/move/lang/parser/partial/assignments.txt @@ -33,7 +33,7 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('call') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') PsiElement())(')') PsiErrorElement:';' expected, got 'let' diff --git a/src/test/resources/org/move/lang/parser/partial/function_calls.move b/src/test/resources/org/move/lang/parser/partial/function_calls.move index 6a293fc77..21d9363c0 100644 --- a/src/test/resources/org/move/lang/parser/partial/function_calls.move +++ b/src/test/resources/org/move/lang/parser/partial/function_calls.move @@ -7,5 +7,7 @@ script { assert() let a = call(,); + call(& ); + call(&mut ); } } diff --git a/src/test/resources/org/move/lang/parser/partial/function_calls.txt b/src/test/resources/org/move/lang/parser/partial/function_calls.txt index 99d298439..f544fc3e3 100644 --- a/src/test/resources/org/move/lang/parser/partial/function_calls.txt +++ b/src/test/resources/org/move/lang/parser/partial/function_calls.txt @@ -20,10 +20,11 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('call') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvLitExprImpl(LIT_EXPR) - PsiElement(INTEGER_LITERAL)('1') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(INTEGER_LITERAL)('1') PsiErrorElement:')' expected, got ';' PsiElement(;)(';') @@ -32,15 +33,16 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('call') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvPlusExprImpl(PLUS_EXPR) - MvLitExprImpl(LIT_EXPR) - PsiElement(INTEGER_LITERAL)('1') - PsiWhiteSpace(' ') - PsiElement(+)('+') - PsiErrorElement: expected, got ')' - + MvValueArgumentImpl(VALUE_ARGUMENT) + MvPlusExprImpl(PLUS_EXPR) + MvLitExprImpl(LIT_EXPR) + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace(' ') + PsiElement(+)('+') + PsiErrorElement: expected, got ')' + PsiElement())(')') PsiElement(;)(';') PsiWhiteSpace('\n ') @@ -48,19 +50,21 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('call') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvLitExprImpl(LIT_EXPR) - PsiElement(INTEGER_LITERAL)('1') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(INTEGER_LITERAL)('1') PsiElement(,)(',') PsiWhiteSpace(' ') - MvPlusExprImpl(PLUS_EXPR) - MvLitExprImpl(LIT_EXPR) - PsiElement(INTEGER_LITERAL)('2') - PsiWhiteSpace(' ') - PsiElement(+)('+') - PsiErrorElement: expected, got ')' - + MvValueArgumentImpl(VALUE_ARGUMENT) + MvPlusExprImpl(PLUS_EXPR) + MvLitExprImpl(LIT_EXPR) + PsiElement(INTEGER_LITERAL)('2') + PsiWhiteSpace(' ') + PsiElement(+)('+') + PsiErrorElement: expected, got ')' + PsiElement())(')') PsiElement(;)(';') PsiWhiteSpace('\n ') @@ -68,16 +72,18 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('call') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvLitExprImpl(LIT_EXPR) - PsiElement(INTEGER_LITERAL)('1') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(INTEGER_LITERAL)('1') PsiElement(,)(',') PsiWhiteSpace(' ') - MvLitExprImpl(LIT_EXPR) - PsiElement(INTEGER_LITERAL)('2') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(INTEGER_LITERAL)('2') PsiElement(,)(',') - PsiErrorElement: expected, got ',' + PsiErrorElement: expected, got ',' PsiElement(,)(',') PsiElement())(')') PsiElement(;)(';') @@ -86,7 +92,7 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('assert') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') PsiElement())(')') PsiErrorElement:';' expected, got 'let' @@ -104,12 +110,43 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('call') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - PsiErrorElement: expected, got ',' + PsiErrorElement: expected, got ',' PsiElement(,)(',') PsiElement())(')') PsiElement(;)(';') + PsiWhiteSpace('\n ') + MvExprStmtImpl(EXPR_STMT) + MvCallExprImpl(CALL_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('call') + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) + PsiElement(()('(') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvBorrowExprImpl(BORROW_EXPR) + PsiElement(&)('&') + PsiErrorElement: expected, got ')' + + PsiWhiteSpace(' ') + PsiElement())(')') + PsiElement(;)(';') + PsiWhiteSpace('\n ') + MvExprStmtImpl(EXPR_STMT) + MvCallExprImpl(CALL_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('call') + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) + PsiElement(()('(') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvBorrowExprImpl(BORROW_EXPR) + PsiElement(&)('&') + PsiElement(mut)('mut') + PsiErrorElement: expected, got ')' + + PsiWhiteSpace(' ') + PsiElement())(')') + PsiElement(;)(';') PsiWhiteSpace('\n ') PsiElement(})('}') PsiWhiteSpace('\n') diff --git a/src/test/resources/org/move/lang/parser/specs/conditions.txt b/src/test/resources/org/move/lang/parser/specs/conditions.txt index a758d2fe8..f8dccf799 100644 --- a/src/test/resources/org/move/lang/parser/specs/conditions.txt +++ b/src/test/resources/org/move/lang/parser/specs/conditions.txt @@ -172,11 +172,12 @@ FILE MvPathImpl(PATH) PsiElement(IDENTIFIER)('Counter') PsiElement(>)('>') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvRefExprImpl(REF_EXPR) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('a') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('a') PsiElement())(')') PsiElement(.)('.') MvStructDotFieldImpl(STRUCT_DOT_FIELD) @@ -198,11 +199,12 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('old') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvRefExprImpl(REF_EXPR) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('y') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('y') PsiElement())(')') PsiWhiteSpace(' ') PsiElement(<)('<') @@ -237,11 +239,12 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('old') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvRefExprImpl(REF_EXPR) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('x') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('x') PsiElement())(')') PsiWhiteSpace(' ') PsiElement(+)('+') @@ -571,38 +574,40 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('all') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvRefExprImpl(REF_EXPR) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('x') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('x') PsiElement(,)(',') PsiWhiteSpace(' ') - MvLambdaExprImpl(LAMBDA_EXPR) - PsiElement(|)('|') - PsiElement(IDENTIFIER)('y') - PsiElement(,)(',') - PsiWhiteSpace(' ') - PsiElement(IDENTIFIER)('z') - PsiElement(|)('|') - PsiWhiteSpace(' ') - MvPlusExprImpl(PLUS_EXPR) + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLambdaExprImpl(LAMBDA_EXPR) + PsiElement(|)('|') + PsiElement(IDENTIFIER)('y') + PsiElement(,)(',') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('z') + PsiElement(|)('|') + PsiWhiteSpace(' ') MvPlusExprImpl(PLUS_EXPR) - MvRefExprImpl(REF_EXPR) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('x') + MvPlusExprImpl(PLUS_EXPR) + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('x') + PsiWhiteSpace(' ') + PsiElement(+)('+') + PsiWhiteSpace(' ') + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('y') PsiWhiteSpace(' ') PsiElement(+)('+') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) - PsiElement(IDENTIFIER)('y') - PsiWhiteSpace(' ') - PsiElement(+)('+') - PsiWhiteSpace(' ') - MvRefExprImpl(REF_EXPR) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('z') + PsiElement(IDENTIFIER)('z') PsiElement())(')') PsiElement(;)(';') PsiWhiteSpace('\n ') @@ -783,11 +788,12 @@ FILE MvPathImpl(PATH) PsiElement(IDENTIFIER)('R') PsiElement(>)('>') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvRefExprImpl(REF_EXPR) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('a') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('a') PsiElement())(')') PsiWhiteSpace(' ') PsiElement(&&)('&&') @@ -804,11 +810,12 @@ FILE MvPathImpl(PATH) PsiElement(IDENTIFIER)('R') PsiElement(>)('>') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvRefExprImpl(REF_EXPR) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('a') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('a') PsiElement())(')') PsiElement(.)('.') MvStructDotFieldImpl(STRUCT_DOT_FIELD) @@ -843,16 +850,18 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('in_range') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvRefExprImpl(REF_EXPR) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('v') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('v') PsiElement(,)(',') PsiWhiteSpace(' ') - MvRefExprImpl(REF_EXPR) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('i') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('i') PsiElement())(')') PsiWhiteSpace(' ') PsiElement(&&)('&&') @@ -898,11 +907,12 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('range') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvRefExprImpl(REF_EXPR) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('gallery') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('gallery') PsiElement())(')') PsiWhiteSpace(' ') MvQuantWhereImpl(QUANT_WHERE) @@ -969,11 +979,12 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('range') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvRefExprImpl(REF_EXPR) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('gallery') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('gallery') PsiElement())(')') PsiWhiteSpace(' ') MvQuantWhereImpl(QUANT_WHERE) @@ -1037,10 +1048,11 @@ FILE MvPathImpl(PATH) PsiElement(IDENTIFIER)('X') PsiElement(>)('>') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvLitExprImpl(LIT_EXPR) - PsiElement(HEX_INTEGER_LITERAL)('0x0') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(HEX_INTEGER_LITERAL)('0x0') PsiElement())(')') PsiElement(.)('.') MvStructDotFieldImpl(STRUCT_DOT_FIELD) @@ -1059,10 +1071,11 @@ FILE MvPathImpl(PATH) PsiElement(IDENTIFIER)('X') PsiElement(>)('>') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvLitExprImpl(LIT_EXPR) - PsiElement(HEX_INTEGER_LITERAL)('0x1') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(HEX_INTEGER_LITERAL)('0x1') PsiElement())(')') PsiElement(.)('.') MvStructDotFieldImpl(STRUCT_DOT_FIELD) @@ -1085,10 +1098,11 @@ FILE MvPathImpl(PATH) PsiElement(IDENTIFIER)('X') PsiElement(>)('>') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvLitExprImpl(LIT_EXPR) - PsiElement(HEX_INTEGER_LITERAL)('0x0') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(HEX_INTEGER_LITERAL)('0x0') PsiElement())(')') PsiElement(.)('.') MvStructDotFieldImpl(STRUCT_DOT_FIELD) @@ -1107,10 +1121,11 @@ FILE MvPathImpl(PATH) PsiElement(IDENTIFIER)('X') PsiElement(>)('>') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvLitExprImpl(LIT_EXPR) - PsiElement(HEX_INTEGER_LITERAL)('0x1') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + PsiElement(HEX_INTEGER_LITERAL)('0x1') PsiElement())(')') PsiElement(.)('.') MvStructDotFieldImpl(STRUCT_DOT_FIELD) diff --git a/src/test/resources/org/move/lang/parser/specs/forall_exists.txt b/src/test/resources/org/move/lang/parser/specs/forall_exists.txt index dd75ce3c0..449a98ca1 100644 --- a/src/test/resources/org/move/lang/parser/specs/forall_exists.txt +++ b/src/test/resources/org/move/lang/parser/specs/forall_exists.txt @@ -86,24 +86,26 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('old') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvCallExprImpl(CALL_EXPR) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('exists') - MvTypeArgumentListImpl(TYPE_ARGUMENT_LIST) - PsiElement(<)('<') - MvTypeArgumentImpl(TYPE_ARGUMENT) - MvPathTypeImpl(PATH_TYPE) + MvValueArgumentImpl(VALUE_ARGUMENT) + MvCallExprImpl(CALL_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('exists') + MvTypeArgumentListImpl(TYPE_ARGUMENT_LIST) + PsiElement(<)('<') + MvTypeArgumentImpl(TYPE_ARGUMENT) + MvPathTypeImpl(PATH_TYPE) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('u8') + PsiElement(>)('>') + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) + PsiElement(()('(') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) - PsiElement(IDENTIFIER)('u8') - PsiElement(>)('>') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) - PsiElement(()('(') - MvRefExprImpl(REF_EXPR) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('addr1') - PsiElement())(')') + PsiElement(IDENTIFIER)('addr1') + PsiElement())(')') PsiElement())(')') PsiElement(:)(':') PsiWhiteSpace(' ') diff --git a/src/test/resources/org/move/lang/parser/specs/spec_file.txt b/src/test/resources/org/move/lang/parser/specs/spec_file.txt index e47d5eb0f..2e8ba9fd0 100644 --- a/src/test/resources/org/move/lang/parser/specs/spec_file.txt +++ b/src/test/resources/org/move/lang/parser/specs/spec_file.txt @@ -60,14 +60,15 @@ FILE MvPathImpl(PATH) PsiElement(IDENTIFIER)('CurrentTimeMicroseconds') PsiElement(>)('>') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvLitExprImpl(LIT_EXPR) - MvAddressLitImpl(ADDRESS_LIT) - PsiElement(@)('@') - MvAddressRefImpl(ADDRESS_REF) - MvNamedAddressImpl(NAMED_ADDRESS) - PsiElement(IDENTIFIER)('aptos_framework') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + MvAddressLitImpl(ADDRESS_LIT) + PsiElement(@)('@') + MvAddressRefImpl(ADDRESS_REF) + MvNamedAddressImpl(NAMED_ADDRESS) + PsiElement(IDENTIFIER)('aptos_framework') PsiElement())(')') PsiElement(.)('.') MvStructDotFieldImpl(STRUCT_DOT_FIELD) @@ -96,7 +97,7 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('is_genesis') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') PsiElement())(')') PsiWhiteSpace(' ') diff --git a/src/test/resources/org/move/lang/parser/specs/spec_statements.txt b/src/test/resources/org/move/lang/parser/specs/spec_statements.txt index 7053c1b6b..1ff796974 100644 --- a/src/test/resources/org/move/lang/parser/specs/spec_statements.txt +++ b/src/test/resources/org/move/lang/parser/specs/spec_statements.txt @@ -252,20 +252,22 @@ FILE MvPathImpl(PATH) PsiElement(IDENTIFIER)('Window') PsiElement(>)('>') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvCallExprImpl(CALL_EXPR) - MvPathImpl(PATH) - MvModuleRefImpl(MODULE_REF) - PsiElement(IDENTIFIER)('Signer') - PsiElement(::)('::') - PsiElement(IDENTIFIER)('spec_address_of') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) - PsiElement(()('(') - MvRefExprImpl(REF_EXPR) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('to_limit') - PsiElement())(')') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvCallExprImpl(CALL_EXPR) + MvPathImpl(PATH) + MvModuleRefImpl(MODULE_REF) + PsiElement(IDENTIFIER)('Signer') + PsiElement(::)('::') + PsiElement(IDENTIFIER)('spec_address_of') + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) + PsiElement(()('(') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('to_limit') + PsiElement())(')') PsiElement())(')') PsiElement(;)(';') PsiWhiteSpace('\n ') @@ -283,20 +285,22 @@ FILE MvPathImpl(PATH) PsiElement(IDENTIFIER)('Window') PsiElement(>)('>') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvCallExprImpl(CALL_EXPR) - MvPathImpl(PATH) - MvModuleRefImpl(MODULE_REF) - PsiElement(IDENTIFIER)('Signer') - PsiElement(::)('::') - PsiElement(IDENTIFIER)('spec_address_of') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) - PsiElement(()('(') - MvRefExprImpl(REF_EXPR) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('to_limit') - PsiElement())(')') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvCallExprImpl(CALL_EXPR) + MvPathImpl(PATH) + MvModuleRefImpl(MODULE_REF) + PsiElement(IDENTIFIER)('Signer') + PsiElement(::)('::') + PsiElement(IDENTIFIER)('spec_address_of') + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) + PsiElement(()('(') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('to_limit') + PsiElement())(')') PsiElement())(')') PsiElement(;)(';') PsiWhiteSpace('\n\n ') @@ -350,13 +354,14 @@ FILE MvPathImpl(PATH) PsiElement(IDENTIFIER)('CoinType') PsiElement(>)('>') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvLitExprImpl(LIT_EXPR) - MvAddressLitImpl(ADDRESS_LIT) - PsiElement(@)('@') - MvAddressRefImpl(ADDRESS_REF) - PsiElement(DIEM_ADDRESS)('0x1') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvLitExprImpl(LIT_EXPR) + MvAddressLitImpl(ADDRESS_LIT) + PsiElement(@)('@') + MvAddressRefImpl(ADDRESS_REF) + PsiElement(DIEM_ADDRESS)('0x1') PsiElement())(')') PsiElement(;)(';') PsiWhiteSpace('\n ') @@ -374,46 +379,47 @@ FILE MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('TRACE') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvChooseQuantExprImpl(CHOOSE_QUANT_EXPR) - PsiElement(choose_kw)('choose') - PsiWhiteSpace(' ') - MvQuantBindingsImpl(QUANT_BINDINGS) - MvTypeQuantBindingImpl(TYPE_QUANT_BINDING) - MvBindingPatImpl(BINDING_PAT) - PsiElement(IDENTIFIER)('x') - PsiElement(:)(':') - PsiWhiteSpace(' ') - MvPathTypeImpl(PATH_TYPE) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('u64') - PsiWhiteSpace(' ') - MvQuantWhereImpl(QUANT_WHERE) - PsiElement(where_kw)('where') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvChooseQuantExprImpl(CHOOSE_QUANT_EXPR) + PsiElement(choose_kw)('choose') PsiWhiteSpace(' ') - MvAndExprImpl(AND_EXPR) - MvGreaterEqualsExprImpl(GREATER_EQUALS_EXPR) - MvRefExprImpl(REF_EXPR) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('x') + MvQuantBindingsImpl(QUANT_BINDINGS) + MvTypeQuantBindingImpl(TYPE_QUANT_BINDING) + MvBindingPatImpl(BINDING_PAT) + PsiElement(IDENTIFIER)('x') + PsiElement(:)(':') PsiWhiteSpace(' ') - PsiElement(>=)('>=') - PsiWhiteSpace(' ') - MvLitExprImpl(LIT_EXPR) - PsiElement(INTEGER_LITERAL)('4') - PsiWhiteSpace(' ') - PsiElement(&&)('&&') - PsiWhiteSpace(' ') - MvLessEqualsExprImpl(LESS_EQUALS_EXPR) - MvRefExprImpl(REF_EXPR) + MvPathTypeImpl(PATH_TYPE) MvPathImpl(PATH) - PsiElement(IDENTIFIER)('x') + PsiElement(IDENTIFIER)('u64') + PsiWhiteSpace(' ') + MvQuantWhereImpl(QUANT_WHERE) + PsiElement(where_kw)('where') + PsiWhiteSpace(' ') + MvAndExprImpl(AND_EXPR) + MvGreaterEqualsExprImpl(GREATER_EQUALS_EXPR) + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('x') + PsiWhiteSpace(' ') + PsiElement(>=)('>=') + PsiWhiteSpace(' ') + MvLitExprImpl(LIT_EXPR) + PsiElement(INTEGER_LITERAL)('4') PsiWhiteSpace(' ') - PsiElement(<=)('<=') + PsiElement(&&)('&&') PsiWhiteSpace(' ') - MvLitExprImpl(LIT_EXPR) - PsiElement(INTEGER_LITERAL)('5') + MvLessEqualsExprImpl(LESS_EQUALS_EXPR) + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('x') + PsiWhiteSpace(' ') + PsiElement(<=)('<=') + PsiWhiteSpace(' ') + MvLitExprImpl(LIT_EXPR) + PsiElement(INTEGER_LITERAL)('5') PsiElement())(')') PsiElement(;)(';') PsiWhiteSpace('\n\n ') @@ -481,11 +487,12 @@ FILE PsiElement(IDENTIFIER)('Signer') PsiElement(::)('::') PsiElement(IDENTIFIER)('address_of') - MvCallArgumentListImpl(CALL_ARGUMENT_LIST) + MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') - MvRefExprImpl(REF_EXPR) - MvPathImpl(PATH) - PsiElement(IDENTIFIER)('acc') + MvValueArgumentImpl(VALUE_ARGUMENT) + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('acc') PsiElement())(')') PsiWhiteSpace(' ') PsiElement(})('}') From 8fdec0e4a1f408b435138f937daa1852116ecd27 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Sun, 11 Sep 2022 15:36:29 +0200 Subject: [PATCH 05/26] sort completion by abilities for type parameters --- changelog/1.20.0.md | 4 ++- .../org/move/ide/annotator/ErrorAnnotator.kt | 5 +-- .../MvMissingAcquiresInspection.kt | 6 ++-- .../ide/inspections/MvTypeCheckInspection.kt | 2 +- .../MvUnusedAcquiresTypeInspection.kt | 4 +-- .../kotlin/org/move/ide/presentation/ty.kt | 28 +++++++++++++--- .../lang/core/completion/MvLookupElement.kt | 9 +++-- .../providers/MvPathCompletionProvider.kt | 6 ++-- .../org/move/lang/core/psi/ext/MoveExpr.kt | 2 +- .../lang/core/types/infer/ExpectedType.kt | 28 ++++++++++++++-- .../lang/core/types/infer/InferenceContext.kt | 32 ++++++++++-------- .../org/move/lang/core/types/ty/TyFunction.kt | 4 ++- .../org/move/lang/core/types/ty/TyStruct.kt | 2 +- .../utils/tests/types/TypificationTestCase.kt | 19 ++++++++--- .../annotator/errors/BuiltinCallErrorTest.kt | 8 +++++ .../completion/CompletionPrioritiesTest.kt | 24 +++++++------- .../org/move/lang/types/ExpectedTypeTest.kt | 33 ++++++++++++------- 17 files changed, 152 insertions(+), 64 deletions(-) diff --git a/changelog/1.20.0.md b/changelog/1.20.0.md index 6fdfddf41..2173df792 100644 --- a/changelog/1.20.0.md +++ b/changelog/1.20.0.md @@ -8,7 +8,9 @@ TBD TODO: screenshot -* Type-driven smart completion for borrow exprs. +* Sort completion in borrow exprs. + +* Sort completions by abilities in type parameters. ## Fixes diff --git a/src/main/kotlin/org/move/ide/annotator/ErrorAnnotator.kt b/src/main/kotlin/org/move/ide/annotator/ErrorAnnotator.kt index f68da49d6..d858bfe3a 100644 --- a/src/main/kotlin/org/move/ide/annotator/ErrorAnnotator.kt +++ b/src/main/kotlin/org/move/ide/annotator/ErrorAnnotator.kt @@ -3,11 +3,12 @@ package org.move.ide.annotator import com.intellij.lang.annotation.AnnotationHolder import com.intellij.lang.annotation.HighlightSeverity import com.intellij.psi.PsiElement -import org.move.ide.presentation.acquireableIn +import org.move.ide.presentation.canBeAcquiredInModule import org.move.ide.presentation.fullname import org.move.lang.MvElementTypes.R_PAREN import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.* +import org.move.lang.core.types.ty.TyUnknown import org.move.lang.modules import org.move.lang.moveProject import org.move.lang.utils.MvDiagnostic @@ -111,7 +112,7 @@ class ErrorAnnotator : MvAnnotator() { val currentModule = o.containingModule ?: return for (typeArg in explicitTypeArgs) { val ty = typeArg.type.ty() - if (!ty.acquireableIn(currentModule)) { + if (ty !is TyUnknown && !ty.canBeAcquiredInModule(currentModule)) { val typeName = ty.fullname() holder.newAnnotation( HighlightSeverity.ERROR, diff --git a/src/main/kotlin/org/move/ide/inspections/MvMissingAcquiresInspection.kt b/src/main/kotlin/org/move/ide/inspections/MvMissingAcquiresInspection.kt index fb5d6dd37..f9e8ad478 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvMissingAcquiresInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvMissingAcquiresInspection.kt @@ -5,7 +5,7 @@ import com.intellij.codeInspection.ProblemDescriptor import com.intellij.codeInspection.ProblemHighlightType import com.intellij.codeInspection.ProblemsHolder import com.intellij.openapi.project.Project -import org.move.ide.presentation.acquireableIn +import org.move.ide.presentation.canBeAcquiredInModule import org.move.ide.presentation.fullnameNoArgs import org.move.ide.presentation.nameNoArgs import org.move.lang.core.psi.* @@ -13,6 +13,7 @@ import org.move.lang.core.psi.ext.acquiresTys import org.move.lang.core.psi.ext.isMsl import org.move.lang.core.types.infer.inferenceCtx import org.move.lang.core.types.ty.Ty +import org.move.lang.core.types.ty.TyUnknown class MvMissingAcquiresInspection : MvLocalInspectionTool() { @@ -28,7 +29,8 @@ class MvMissingAcquiresInspection : MvLocalInspectionTool() { val inferenceCtx = function.inferenceCtx(callExpr.isMsl()) val missingTys = callExpr.acquiresTys(inferenceCtx) .filter { it.fullnameNoArgs() !in declaredTyFullnames } - .filter { it.acquireableIn(module) } + .filter { it !is TyUnknown } + .filter { it.canBeAcquiredInModule(module) } if (missingTys.isNotEmpty()) { val name = function.name ?: return diff --git a/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt b/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt index 49a389bdc..7fa6d465b 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt @@ -120,7 +120,7 @@ class MvTypeCheckInspection : MvLocalInspectionTool() { val message = "The type '${fieldTy.name()}' does not have the ability '${requiredAbility.label()}' " + "required by the declared ability '${ability.label()}' " + - "of the struct '${TyStruct(field.struct, listOf(), mapOf()).name()}'" + "of the struct '${TyStruct(field.struct, listOf(), mapOf(), listOf()).name()}'" holder.registerTypeError(field, message) return } diff --git a/src/main/kotlin/org/move/ide/inspections/MvUnusedAcquiresTypeInspection.kt b/src/main/kotlin/org/move/ide/inspections/MvUnusedAcquiresTypeInspection.kt index c58e665ca..4df94cd3d 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvUnusedAcquiresTypeInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvUnusedAcquiresTypeInspection.kt @@ -6,7 +6,7 @@ import com.intellij.codeInspection.ProblemsHolder import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement import com.intellij.psi.util.descendantsOfType -import org.move.ide.presentation.acquireableIn +import org.move.ide.presentation.canBeAcquiredInModule import org.move.ide.presentation.fullnameNoArgs import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.acquiresTys @@ -59,7 +59,7 @@ class MvUnusedAcquiresTypeInspection : MvLocalInspectionTool() { for ((i, pathType) in pathTypes.withIndex()) { // check that this acquires is allowed in the context val ty = pathType.ty() - if (!ty.acquireableIn(module)) { + if (!ty.canBeAcquiredInModule(module)) { unusedAcquiresIndices.add(i) continue } diff --git a/src/main/kotlin/org/move/ide/presentation/ty.kt b/src/main/kotlin/org/move/ide/presentation/ty.kt index 7ca7aa998..79e84b213 100644 --- a/src/main/kotlin/org/move/ide/presentation/ty.kt +++ b/src/main/kotlin/org/move/ide/presentation/ty.kt @@ -5,7 +5,8 @@ import org.move.lang.core.psi.MvModule import org.move.lang.core.psi.containingModule import org.move.lang.core.types.ty.* -fun Ty.acquireableIn(mod: MvModule): Boolean { +fun Ty.canBeAcquiredInModule(mod: MvModule): Boolean { + if (this is TyUnknown) return true // no declaring module means builtin val declaringMod = this.declaringModule ?: return false return declaringMod == mod @@ -61,6 +62,22 @@ fun Ty.text(fq: Boolean = false): String = fq = fq ) +fun Ty.expectedTyText(): String { + return render( + this, + level = 3, + typeVar = { + val name = "?${it.origin?.name ?: "_"}" + val abilities = + it.abilities() + .toList().sorted() + .joinToString(", ", "(", ")") { a -> a.label() } + "$name$abilities" + }, + fq = true + ) +} + val Ty.insertionSafeText: String get() = render( this, @@ -78,6 +95,7 @@ private fun render( unknown: String = "", anonymous: String = "", integer: String = "integer", + typeVar: (TyInfer.TyVar) -> String = { "?${it.origin?.name ?: "_"}" }, fq: Boolean = false ): String { check(level >= 0) @@ -103,7 +121,7 @@ private fun render( if (level == 0) return "_" - val r = { subTy: Ty -> render(subTy, level - 1, unknown, anonymous, integer, fq) } + val r = { subTy: Ty -> render(subTy, level - 1, unknown, anonymous, integer, typeVar, fq) } return when (ty) { is TyFunction -> { @@ -115,9 +133,9 @@ private fun render( s } is TyTuple -> ty.types.joinToString(", ", "(", ")", transform = r) - is TyVector -> "vector<${render(ty.item, level, unknown, anonymous, integer, fq)}>" + is TyVector -> "vector<${render(ty.item, level, unknown, anonymous, integer, typeVar, fq)}>" is TyReference -> "${if (ty.permissions.contains(RefPermissions.WRITE)) "&mut " else "&"}${ - render(ty.referenced, level, unknown, anonymous, integer, fq) + render(ty.referenced, level, unknown, anonymous, integer, typeVar, fq) }" // is TyTraitObject -> ty.trait.name ?: anonymous is TyTypeParameter -> ty.name ?: anonymous @@ -129,7 +147,7 @@ private fun render( name + args } is TyInfer -> when (ty) { - is TyInfer.TyVar -> "?${ty.origin?.name ?: "_"}" + is TyInfer.TyVar -> typeVar(ty) is TyInfer.IntVar -> integer } else -> error("unreachable") diff --git a/src/main/kotlin/org/move/lang/core/completion/MvLookupElement.kt b/src/main/kotlin/org/move/lang/core/completion/MvLookupElement.kt index 504052e82..ac709cd27 100644 --- a/src/main/kotlin/org/move/lang/core/completion/MvLookupElement.kt +++ b/src/main/kotlin/org/move/lang/core/completion/MvLookupElement.kt @@ -5,11 +5,14 @@ import com.intellij.codeInsight.lookup.LookupElementDecorator import org.move.lang.core.psi.MvBindingPat import org.move.lang.core.psi.MvFunction import org.move.lang.core.psi.MvNamedElement +import org.move.lang.core.psi.MvStruct import org.move.lang.core.psi.ext.inferredTy import org.move.lang.core.psi.returnTy import org.move.lang.core.types.infer.InferenceContext +import org.move.lang.core.types.infer.instantiateItemTy import org.move.lang.core.types.infer.isCompatible import org.move.lang.core.types.ty.Ty +import org.move.lang.core.types.ty.TyStruct import org.move.lang.core.types.ty.TyUnknown fun LookupElement.toMvLookupElement(properties: LookupElementProperties): MvLookupElement = @@ -66,7 +69,9 @@ fun lookupProperties(element: MvNamedElement, context: CompletionContext): Looku val expectedTy = context.expectedTy if (expectedTy != null) { val ty = element.asTy(ctx) - props = props.copy(isReturnTypeConformsToExpectedType = isCompatible(context.expectedTy, ty)) + props = props.copy( + isReturnTypeConformsToExpectedType = isCompatible(context.expectedTy, ty, ctx.msl) + ) } return props } @@ -75,7 +80,7 @@ private fun MvNamedElement.asTy(ctx: InferenceContext): Ty = when (this) { // is RsFieldDecl -> typeReference?.type is MvFunction -> this.returnTy -// is RsStructItem -> declaredType + is MvStruct -> instantiateItemTy(this, ctx.msl) is MvBindingPat -> this.inferredTy(ctx) else -> TyUnknown } diff --git a/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider.kt b/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider.kt index d878b4af4..cd7bb9770 100644 --- a/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider.kt +++ b/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider.kt @@ -19,6 +19,7 @@ import org.move.lang.core.resolve.ref.Visibility import org.move.lang.core.resolve.ref.processModuleItems import org.move.lang.core.types.infer.InferenceContext import org.move.lang.core.types.infer.functionInferenceCtx +import org.move.lang.core.types.infer.inferExpectedTy import org.move.lang.core.types.ty.Ty abstract class MvPathCompletionProvider : MvCompletionProvider() { @@ -145,8 +146,9 @@ private fun getExpectedTypeForEnclosingPathOrDotExpr(element: MvReferenceElement if (element.endOffset < ancestor.endOffset) continue if (element.endOffset > ancestor.endOffset) break when (ancestor) { - is MvRefExpr -> return ancestor.expectedTy(ctx) - is MvDotExpr -> return ancestor.expectedTy(ctx) + is MvPathType, + is MvRefExpr, + is MvDotExpr -> return inferExpectedTy(ancestor, ctx) } } return null diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MoveExpr.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MoveExpr.kt index c5b2f4446..a0192d618 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MoveExpr.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MoveExpr.kt @@ -18,4 +18,4 @@ fun MvExpr.inferredTy(): Ty { return inferExprTy(this, inferenceCtx) } -fun MvExpr.expectedTy(ctx: InferenceContext): Ty? = inferExpectedTy(this, ctx) +//fun MvExpr.expectedTy(ctx: InferenceContext): Ty? = inferExpectedTy(this, ctx) diff --git a/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt b/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt index afad5df1d..f5006bc08 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt @@ -1,26 +1,50 @@ package org.move.lang.core.types.infer +import com.intellij.psi.PsiElement import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.declaredTy import org.move.lang.core.psi.ext.isMsl import org.move.lang.core.psi.ext.ty import org.move.lang.core.types.ty.Ty import org.move.lang.core.types.ty.TyReference +import org.move.lang.core.types.ty.TyStruct import org.move.lang.core.types.ty.TyUnknown -fun inferExpectedTy(element: MvElement, ctx: InferenceContext): Ty? { +fun inferExpectedTy(element: PsiElement, ctx: InferenceContext): Ty? { val owner = element.parent return when (owner) { is MvBorrowExpr -> { val refTy = inferExpectedTy(owner, ctx) as? TyReference ?: return null refTy.innerTy() } + is MvTypeArgument -> { + val typeArgumentList = owner.parent as MvTypeArgumentList + val paramIndex = + typeArgumentList.children.indexOfFirst { it.textRange.contains(owner.textOffset) } + if (paramIndex == -1) return null + val path = typeArgumentList.parent as MvPath + val ownerExpr = path.parent + when (ownerExpr) { + is MvCallExpr -> { + val inferenceCtx = ownerExpr.functionInferenceCtx(ownerExpr.isMsl()) + inferenceCtx.callExprTypes[ownerExpr] + ?.typeVars + ?.getOrNull(paramIndex) + } + is MvStructLitExpr -> { + val inferenceCtx = ownerExpr.functionInferenceCtx(ownerExpr.isMsl()) + (inferenceCtx.exprTypes[ownerExpr] as? TyStruct) + ?.typeArgs + ?.getOrNull(paramIndex) + } + else -> null + } + } is MvValueArgument -> { val valueArgumentList = owner.parent as MvValueArgumentList val paramIndex = valueArgumentList.children.indexOfFirst { it.textRange.contains(owner.textOffset) } if (paramIndex == -1) return null - val callExpr = valueArgumentList.parent as? MvCallExpr ?: return null val inferenceCtx = callExpr.functionInferenceCtx(callExpr.isMsl()) inferenceCtx.callExprTypes[callExpr] diff --git a/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt b/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt index 579769c65..fc8be3fde 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt @@ -120,7 +120,8 @@ fun instantiateItemTy(item: MvNameIdentifierOwner, msl: Boolean): Ty { instantiateItemTy(acqItem, msl) .foldTyTypeParameterWith { tp -> findTypeVar(tp.parameter) } } - TyFunction(item, typeVars, paramTypes, retTy, acqTys) + val typeArgs = item.typeParameters.map { findTypeVar(it) } + TyFunction(item, typeVars, paramTypes, retTy, acqTys, typeArgs) } is MvTypeParameter -> item.ty() @@ -128,17 +129,17 @@ fun instantiateItemTy(item: MvNameIdentifierOwner, msl: Boolean): Ty { } } -fun isCompatibleReferences(expectedTy: TyReference, inferredTy: TyReference): Boolean { - return isCompatible(expectedTy.referenced, inferredTy.referenced) +fun isCompatibleReferences(expectedTy: TyReference, inferredTy: TyReference, msl: Boolean): Boolean { + return isCompatible(expectedTy.referenced, inferredTy.referenced, msl) } -fun isCompatibleStructs(expectedTy: TyStruct, inferredTy: TyStruct): Boolean { +fun isCompatibleStructs(expectedTy: TyStruct, inferredTy: TyStruct, msl: Boolean): Boolean { return expectedTy.item.fqName == inferredTy.item.fqName && expectedTy.typeArgs.size == inferredTy.typeArgs.size - && expectedTy.typeArgs.zip(inferredTy.typeArgs).all { isCompatible(it.first, it.second) } + && expectedTy.typeArgs.zip(inferredTy.typeArgs).all { isCompatible(it.first, it.second, msl) } } -fun isCompatibleTuples(expectedTy: TyTuple, inferredTy: TyTuple): Boolean { +fun isCompatibleTuples(expectedTy: TyTuple, inferredTy: TyTuple, msl: Boolean): Boolean { return expectedTy.types.size == inferredTy.types.size && expectedTy.types.zip(inferredTy.types).all { isCompatible(it.first, it.second) } } @@ -163,14 +164,19 @@ fun combineTys(ty1: Ty, ty2: Ty): Ty { } } -fun isCompatible(rawExpectedTy: Ty, rawInferredTy: Ty): Boolean { +fun isCompatible(rawExpectedTy: Ty, rawInferredTy: Ty, msl: Boolean = true): Boolean { val expectedTy = rawExpectedTy.mslTy() val inferredTy = rawInferredTy.mslTy() return when { expectedTy is TyNever || inferredTy is TyNever -> true expectedTy is TyUnknown || inferredTy is TyUnknown -> true - expectedTy is TyInfer.TyVar || inferredTy is TyInfer.TyVar -> { - // check abilities + expectedTy is TyInfer.TyVar -> { + val compat = isCompatibleAbilities(expectedTy, inferredTy, msl) + compat == Compat.Yes + } + /* expectedTy !is TyInfer.TyVar && */ inferredTy is TyInfer.TyVar -> { + // todo: should always be false + // todo: can it ever occur anyway? true } expectedTy is TyInfer.IntVar && (inferredTy is TyInfer.IntVar || inferredTy is TyInteger) -> { @@ -192,15 +198,15 @@ fun isCompatible(rawExpectedTy: Ty, rawInferredTy: Ty): Boolean { && expectedTy.name == inferredTy.name -> true expectedTy is TyVector && inferredTy is TyVector - && isCompatible(expectedTy.item, inferredTy.item) -> true + && isCompatible(expectedTy.item, inferredTy.item, msl) -> true expectedTy is TyReference && inferredTy is TyReference // inferredTy permissions should be a superset of expectedTy permissions && (expectedTy.permissions - inferredTy.permissions).isEmpty() -> - isCompatibleReferences(expectedTy, inferredTy) + isCompatibleReferences(expectedTy, inferredTy, msl) - expectedTy is TyStruct && inferredTy is TyStruct -> isCompatibleStructs(expectedTy, inferredTy) - expectedTy is TyTuple && inferredTy is TyTuple -> isCompatibleTuples(expectedTy, inferredTy) + expectedTy is TyStruct && inferredTy is TyStruct -> isCompatibleStructs(expectedTy, inferredTy, msl) + expectedTy is TyTuple && inferredTy is TyTuple -> isCompatibleTuples(expectedTy, inferredTy, msl) else -> false } } diff --git a/src/main/kotlin/org/move/lang/core/types/ty/TyFunction.kt b/src/main/kotlin/org/move/lang/core/types/ty/TyFunction.kt index 9a1b8f5b4..43bd0dc3c 100644 --- a/src/main/kotlin/org/move/lang/core/types/ty/TyFunction.kt +++ b/src/main/kotlin/org/move/lang/core/types/ty/TyFunction.kt @@ -11,6 +11,7 @@ class TyFunction( val paramTypes: List, val retType: Ty, val acquiresTypes: List, + val typeArgs: List, ) : Ty { var solvable: Boolean = true @@ -20,7 +21,8 @@ class TyFunction( typeVars, paramTypes.map { it.foldWith(folder) }, retType.foldWith(folder), - acquiresTypes.map { it.foldWith(folder) } + acquiresTypes.map { it.foldWith(folder) }, + typeArgs.map(folder) ) } diff --git a/src/main/kotlin/org/move/lang/core/types/ty/TyStruct.kt b/src/main/kotlin/org/move/lang/core/types/ty/TyStruct.kt index f33b6c5b6..cb75b8eac 100644 --- a/src/main/kotlin/org/move/lang/core/types/ty/TyStruct.kt +++ b/src/main/kotlin/org/move/lang/core/types/ty/TyStruct.kt @@ -13,7 +13,7 @@ data class TyStruct( val item: MvStruct, val typeVars: List, val fieldTys: Map, - var typeArgs: List = emptyList() + var typeArgs: List ) : Ty { override fun abilities(): Set = this.item.tyAbilities diff --git a/src/main/kotlin/org/move/utils/tests/types/TypificationTestCase.kt b/src/main/kotlin/org/move/utils/tests/types/TypificationTestCase.kt index 49bf8c11f..4e910b283 100644 --- a/src/main/kotlin/org/move/utils/tests/types/TypificationTestCase.kt +++ b/src/main/kotlin/org/move/utils/tests/types/TypificationTestCase.kt @@ -1,10 +1,11 @@ package org.move.utils.tests.types import org.intellij.lang.annotations.Language +import org.move.ide.presentation.expectedTyText import org.move.ide.presentation.text import org.move.lang.core.psi.MvElement import org.move.lang.core.psi.MvExpr -import org.move.lang.core.psi.ext.expectedTy +import org.move.lang.core.psi.MvType import org.move.lang.core.psi.ext.inferredTy import org.move.lang.core.psi.ext.isMsl import org.move.lang.core.types.infer.functionInferenceCtx @@ -14,13 +15,21 @@ import org.move.utils.tests.MvTestBase import org.move.utils.tests.base.findElementAndDataInEditor abstract class TypificationTestCase : MvTestBase() { - protected fun testExpectedTypeExpr(@Language("Move") code: String) { + protected fun testExpectedTyExpr(@Language("Move") code: String) { + testExpectedType(code) + } + + protected fun testExpectedTyType(@Language("Move") code: String) { + testExpectedType(code) + } + + protected inline fun testExpectedType(@Language("Move") code: String) { InlineFile(myFixture, code, "main.move") - val (expr, data) = myFixture.findElementAndDataInEditor() + val (element, data) = myFixture.findElementAndDataInEditor() val expectedType = data.trim() - val ctx = expr.functionInferenceCtx(expr.isMsl()) - val actualType = expr.expectedTy(ctx)?.text(true) ?: "null" + val ctx = element.functionInferenceCtx(element.isMsl()) + val actualType = inferExpectedTy(element, ctx)?.expectedTyText() ?: "null" check(actualType == expectedType) { "Type mismatch. Expected $expectedType, found: $actualType" } diff --git a/src/test/kotlin/org/move/ide/annotator/errors/BuiltinCallErrorTest.kt b/src/test/kotlin/org/move/ide/annotator/errors/BuiltinCallErrorTest.kt index f14651aa0..8cf9fabcb 100644 --- a/src/test/kotlin/org/move/ide/annotator/errors/BuiltinCallErrorTest.kt +++ b/src/test/kotlin/org/move/ide/annotator/errors/BuiltinCallErrorTest.kt @@ -18,6 +18,14 @@ class BuiltinCallErrorTest: AnnotatorTestCase(ErrorAnnotator::class) { } """) + fun `test no error if type is unresolved`() = checkErrors(""" + module 0x1::Main { + fun m() { + borrow_global(@0x1); + } + } + """) + fun `test no global storage access error in spec`() = checkErrors(""" module 0x1::M { struct S1 has key {} diff --git a/src/test/kotlin/org/move/lang/completion/CompletionPrioritiesTest.kt b/src/test/kotlin/org/move/lang/completion/CompletionPrioritiesTest.kt index 0ae239d9e..b74ce6025 100644 --- a/src/test/kotlin/org/move/lang/completion/CompletionPrioritiesTest.kt +++ b/src/test/kotlin/org/move/lang/completion/CompletionPrioritiesTest.kt @@ -95,18 +95,18 @@ module 0x1::Main { } """) -// fun `test resource before non-resource in borrow_global`() = checkCompletionsOrder( -// listOf("Coin", "Cat"), -// """ -//module 0x1::Main { -// struct Cat {} -// struct Coin has key {} -// fun call() { -// borrow_global(@0x1); -// } -//} -// """ -// ) + fun `test resource before non-resource in borrow_global`() = checkCompletionsOrder( + listOf("Coin", "Cat"), + """ +module 0x1::Main { + struct Cat {} + struct Coin has key {} + fun call() { + borrow_global(@0x1); + } +} + """ + ) fun checkCompletionsOrder(listStart: List, @Language("Move") code: String) { val variants = completionFixture.invokeCompletion(code) diff --git a/src/test/kotlin/org/move/lang/types/ExpectedTypeTest.kt b/src/test/kotlin/org/move/lang/types/ExpectedTypeTest.kt index 5fb20bace..8baf8abef 100644 --- a/src/test/kotlin/org/move/lang/types/ExpectedTypeTest.kt +++ b/src/test/kotlin/org/move/lang/types/ExpectedTypeTest.kt @@ -3,7 +3,7 @@ package org.move.lang.types import org.move.utils.tests.types.TypificationTestCase class ExpectedTypeTest : TypificationTestCase() { - fun `test function parameter primitive type`() = testExpectedTypeExpr( + fun `test function parameter primitive type`() = testExpectedTyExpr( """ module 0x1::Main { fun call(a: u8) {} @@ -15,7 +15,7 @@ class ExpectedTypeTest : TypificationTestCase() { """ ) - fun `test function parameter generic explicit type`() = testExpectedTypeExpr( + fun `test function parameter generic explicit type`() = testExpectedTyExpr( """ module 0x1::Main { fun call(a: T) {} @@ -27,7 +27,7 @@ class ExpectedTypeTest : TypificationTestCase() { """ ) - fun `test function parameter gets type from first parameter`() = testExpectedTypeExpr(""" + fun `test function parameter gets type from first parameter`() = testExpectedTyExpr(""" module 0x1::Main { fun call(a: T, b: T) {} fun main() { @@ -37,7 +37,7 @@ class ExpectedTypeTest : TypificationTestCase() { } """) - fun `test null if too many parameters`() = testExpectedTypeExpr(""" + fun `test null if too many parameters`() = testExpectedTyExpr(""" module 0x1::Main { fun call(a: T, b: T) {} fun main() { @@ -47,7 +47,7 @@ class ExpectedTypeTest : TypificationTestCase() { } """) - fun `test inferred correctly if not enough parameters`() = testExpectedTypeExpr(""" + fun `test inferred correctly if not enough parameters`() = testExpectedTyExpr(""" module 0x1::Main { fun call(a: T, b: T, c: T) {} fun main() { @@ -57,7 +57,7 @@ class ExpectedTypeTest : TypificationTestCase() { } """) - fun `test inferred from return type`() = testExpectedTypeExpr(""" + fun `test inferred from return type`() = testExpectedTyExpr(""" module 0x1::Main { fun identity(a: T): T { a } fun main() { @@ -67,7 +67,7 @@ class ExpectedTypeTest : TypificationTestCase() { } """) - fun `test let statement initializer no pattern explicit type`() = testExpectedTypeExpr( + fun `test let statement initializer no pattern explicit type`() = testExpectedTyExpr( """ module 0x1::Main { fun main() { @@ -78,7 +78,7 @@ class ExpectedTypeTest : TypificationTestCase() { """ ) - fun `test let statement struct pattern`() = testExpectedTypeExpr( + fun `test let statement struct pattern`() = testExpectedTyExpr( """ module 0x1::Main { struct S { val: u8 } @@ -90,7 +90,7 @@ class ExpectedTypeTest : TypificationTestCase() { """ ) - fun `test struct field literal`() = testExpectedTypeExpr( + fun `test struct field literal`() = testExpectedTyExpr( """ module 0x1::Main { struct S { val: u8 } @@ -102,7 +102,7 @@ class ExpectedTypeTest : TypificationTestCase() { """ ) - fun `test null if inside other expr`() = testExpectedTypeExpr( + fun `test null if inside other expr`() = testExpectedTyExpr( """ module 0x1::Main { fun call() { @@ -113,7 +113,7 @@ class ExpectedTypeTest : TypificationTestCase() { """ ) - fun `test borrow type`() = testExpectedTypeExpr(""" + fun `test borrow type`() = testExpectedTyExpr(""" module 0x1::main { struct LiquidityPool {} fun call(pool: &LiquidityPool) {} @@ -124,7 +124,7 @@ class ExpectedTypeTest : TypificationTestCase() { } """) - fun `test borrow mut type`() = testExpectedTypeExpr(""" + fun `test borrow mut type`() = testExpectedTyExpr(""" module 0x1::main { struct LiquidityPool {} fun call(pool: &mut LiquidityPool) {} @@ -134,4 +134,13 @@ class ExpectedTypeTest : TypificationTestCase() { } } """) + + fun `test type argument type`() = testExpectedTyType(""" + module 0x1::main { + fun main() { + borrow_global(); + //^ ?T(key) + } + } + """) } From cd70d08b37dae50342746425d4a5d0e8fabd4f98 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Sun, 11 Sep 2022 18:19:04 +0200 Subject: [PATCH 06/26] fix type checking caching --- build.gradle.kts | 10 ++-- changelog/1.20.0.md | 2 + gradle.properties | 2 +- src/main/kotlin/org/move/cli/MoveProject.kt | 3 +- .../ide/hints/FunctionParameterInfoHandler.kt | 2 +- .../hints/StructLiteralFieldsInfoHandler.kt | 2 +- .../kotlin/org/move/ide/utils/CallInfo.kt | 18 +++--- .../org/move/lang/core/MoveParserUtil.kt | 1 - .../lang/core/completion/MvLookupElement.kt | 7 +-- .../providers/MvPathCompletionProvider.kt | 5 +- .../org/move/lang/core/psi/ext/MoveExpr.kt | 2 - .../move/lang/core/psi/ext/MoveModuleDef.kt | 55 ++++++++----------- .../org/move/lang/core/psi/ext/MvCallExpr.kt | 2 +- .../move/lang/core/types/infer/Expressions.kt | 4 +- .../lang/core/types/infer/InferenceContext.kt | 38 +++++++------ .../inspections/MvTypeCheckInspectionTest.kt | 28 ++++++++++ .../move/lang/types/ExpressionTypesTest.kt | 29 ++++++++++ 17 files changed, 131 insertions(+), 79 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index c84f0becb..bd8c4aed8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,17 +4,17 @@ import org.jetbrains.intellij.tasks.RunPluginVerifierTask import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import java.util.* -val shortPlatformVersion = prop("shortPlatformVersion") +val platformVersion = prop("shortPlatformVersion") val publishingToken = System.getenv("JB_PUB_TOKEN") ?: null fun prop(name: String): String = extra.properties[name] as? String - ?: error("Property `$name` is not defined in gradle.properties for environment `$shortPlatformVersion`") + ?: error("Property `$name` is not defined in gradle.properties for environment `$platformVersion`") //val intellijVersion = prop("intellijVersion", "2021.2") val kotlinVersion = "1.7.10" -val pluginJarName = "intellij-move-$shortPlatformVersion" +val pluginJarName = "intellij-move-$platformVersion" val pluginVersion = "1.20.0" val pluginGroup = "org.move" @@ -62,6 +62,8 @@ allprojects { configure { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 +// sourceCompatibility = (if (platformVersion == "222") JavaVersion.VERSION_17 else JavaVersion.VERSION_11) +// targetCompatibility = (if (platformVersion == "222") JavaVersion.VERSION_17 else JavaVersion.VERSION_11) } sourceSets { @@ -100,7 +102,7 @@ allprojects { } patchPluginXml { - version.set("$pluginVersion.$shortPlatformVersion") + version.set("$pluginVersion.$platformVersion") changeNotes.set("""

diff --git a/changelog/1.20.0.md b/changelog/1.20.0.md index 2173df792..9308268a1 100644 --- a/changelog/1.20.0.md +++ b/changelog/1.20.0.md @@ -16,4 +16,6 @@ TODO: screenshot * Allow spaces inside `public(friend)` function modifier. +* Fix caching issue that lead to undeterministic type checking in some cases. + ## Internal diff --git a/gradle.properties b/gradle.properties index eba3e1e23..163aa24eb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,4 +14,4 @@ propertiesPluginEnvironmentNameProperty=shortPlatformVersion # properties files # supported versions are 212, 213, 221, 222, default is 212 # pass ORG_GRADLE_PROJECT_shortPlatformVersion environment variable to overwrite -shortPlatformVersion=212 +shortPlatformVersion=222 diff --git a/src/main/kotlin/org/move/cli/MoveProject.kt b/src/main/kotlin/org/move/cli/MoveProject.kt index 1b0723f3b..b0c5a457e 100644 --- a/src/main/kotlin/org/move/cli/MoveProject.kt +++ b/src/main/kotlin/org/move/cli/MoveProject.kt @@ -45,7 +45,8 @@ data class MoveProject( fun addresses(): PackageAddresses { return CachedValuesManager.getManager(this.project).getCachedValue(this) { - val packageName = currentPackage.packageName + val packageName = this.currentPackage.packageName + val cumulativeAddresses = PackageAddresses(mutableAddressMap(), placeholderMap()) for ((depPackage, subst) in this.dependencies) { cumulativeAddresses.extendWith(depPackage.addresses()) diff --git a/src/main/kotlin/org/move/ide/hints/FunctionParameterInfoHandler.kt b/src/main/kotlin/org/move/ide/hints/FunctionParameterInfoHandler.kt index 5cf77afae..0e410802b 100644 --- a/src/main/kotlin/org/move/ide/hints/FunctionParameterInfoHandler.kt +++ b/src/main/kotlin/org/move/ide/hints/FunctionParameterInfoHandler.kt @@ -7,9 +7,9 @@ import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiFile import org.move.ide.utils.CallInfo import org.move.lang.MvElementTypes -import org.move.lang.core.psi.MvValueArgumentList import org.move.lang.core.psi.MvCallExpr import org.move.lang.core.psi.MvStructLitFieldsBlock +import org.move.lang.core.psi.MvValueArgumentList import org.move.lang.core.psi.ext.ancestorOrSelf import org.move.lang.core.psi.ext.startOffset import org.move.utils.AsyncParameterInfoHandler diff --git a/src/main/kotlin/org/move/ide/hints/StructLiteralFieldsInfoHandler.kt b/src/main/kotlin/org/move/ide/hints/StructLiteralFieldsInfoHandler.kt index 85e1cc1a1..92b5ffcb6 100644 --- a/src/main/kotlin/org/move/ide/hints/StructLiteralFieldsInfoHandler.kt +++ b/src/main/kotlin/org/move/ide/hints/StructLiteralFieldsInfoHandler.kt @@ -8,9 +8,9 @@ import com.intellij.psi.PsiFile import com.intellij.psi.tree.IElementType import org.move.ide.presentation.fullname import org.move.lang.MvElementTypes -import org.move.lang.core.psi.MvValueArgumentList import org.move.lang.core.psi.MvStructLitField import org.move.lang.core.psi.MvStructLitFieldsBlock +import org.move.lang.core.psi.MvValueArgumentList import org.move.lang.core.psi.ext.* import org.move.utils.AsyncParameterInfoHandler diff --git a/src/main/kotlin/org/move/ide/utils/CallInfo.kt b/src/main/kotlin/org/move/ide/utils/CallInfo.kt index 9543e1730..bed8bbe03 100644 --- a/src/main/kotlin/org/move/ide/utils/CallInfo.kt +++ b/src/main/kotlin/org/move/ide/utils/CallInfo.kt @@ -5,26 +5,24 @@ package org.move.ide.utils -import com.intellij.psi.util.CachedValueProvider -import com.intellij.psi.util.CachedValuesManager -import com.intellij.psi.util.PsiModificationTracker +import com.intellij.psi.util.CachedValuesManager.getProjectPsiDependentCache import org.move.lang.core.psi.MvCallExpr import org.move.lang.core.psi.MvFunction import org.move.lang.core.psi.parameters val MvFunction.callInfo: CallInfo? - get() = CachedValuesManager.getCachedValue(this) { - val name = this.name ?: return@getCachedValue null + get() = getProjectPsiDependentCache(this) { + val name = it.name ?: return@getProjectPsiDependentCache null - val parameters = this.parameters.map { - val paramName = it.bindingPat.name - val paramType = it.typeAnnotation?.type + val parameters = it.parameters.map { param -> + val paramName = param.bindingPat.name + val paramType = param.typeAnnotation?.type if (paramName == null || paramType == null) { - return@getCachedValue null + return@getProjectPsiDependentCache null } CallInfo.Parameter(paramName, paramType.text) } - CachedValueProvider.Result(CallInfo(name, parameters), PsiModificationTracker.MODIFICATION_COUNT) + CallInfo(name, parameters) } class CallInfo( diff --git a/src/main/kotlin/org/move/lang/core/MoveParserUtil.kt b/src/main/kotlin/org/move/lang/core/MoveParserUtil.kt index a0b624190..4b5e39b70 100644 --- a/src/main/kotlin/org/move/lang/core/MoveParserUtil.kt +++ b/src/main/kotlin/org/move/lang/core/MoveParserUtil.kt @@ -3,7 +3,6 @@ package org.move.lang.core import com.intellij.lang.PsiBuilder import com.intellij.lang.PsiBuilderUtil import com.intellij.lang.WhitespacesAndCommentsBinder -import com.intellij.lang.WhitespacesBinders import com.intellij.lang.parser.GeneratedParserUtilBase import com.intellij.openapi.util.Key import com.intellij.psi.TokenType.WHITE_SPACE diff --git a/src/main/kotlin/org/move/lang/core/completion/MvLookupElement.kt b/src/main/kotlin/org/move/lang/core/completion/MvLookupElement.kt index ac709cd27..eb5d0b217 100644 --- a/src/main/kotlin/org/move/lang/core/completion/MvLookupElement.kt +++ b/src/main/kotlin/org/move/lang/core/completion/MvLookupElement.kt @@ -2,17 +2,12 @@ package org.move.lang.core.completion import com.intellij.codeInsight.lookup.LookupElement import com.intellij.codeInsight.lookup.LookupElementDecorator -import org.move.lang.core.psi.MvBindingPat -import org.move.lang.core.psi.MvFunction -import org.move.lang.core.psi.MvNamedElement -import org.move.lang.core.psi.MvStruct +import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.inferredTy -import org.move.lang.core.psi.returnTy import org.move.lang.core.types.infer.InferenceContext import org.move.lang.core.types.infer.instantiateItemTy import org.move.lang.core.types.infer.isCompatible import org.move.lang.core.types.ty.Ty -import org.move.lang.core.types.ty.TyStruct import org.move.lang.core.types.ty.TyUnknown fun LookupElement.toMvLookupElement(properties: LookupElementProperties): MvLookupElement = diff --git a/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider.kt b/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider.kt index cd7bb9770..9e82e5cb4 100644 --- a/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider.kt +++ b/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider.kt @@ -12,7 +12,10 @@ import org.move.lang.core.completion.CompletionContext import org.move.lang.core.completion.UNIMPORTED_ITEM_PRIORITY import org.move.lang.core.completion.createLookupElement import org.move.lang.core.psi.* -import org.move.lang.core.psi.ext.* +import org.move.lang.core.psi.ext.ancestors +import org.move.lang.core.psi.ext.endOffset +import org.move.lang.core.psi.ext.isSelf +import org.move.lang.core.psi.ext.itemScope import org.move.lang.core.resolve.* import org.move.lang.core.resolve.ref.Namespace import org.move.lang.core.resolve.ref.Visibility diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MoveExpr.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MoveExpr.kt index a0192d618..83acf2384 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MoveExpr.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MoveExpr.kt @@ -1,9 +1,7 @@ package org.move.lang.core.psi.ext import org.move.lang.core.psi.MvExpr -import org.move.lang.core.types.infer.InferenceContext import org.move.lang.core.types.infer.functionInferenceCtx -import org.move.lang.core.types.infer.inferExpectedTy import org.move.lang.core.types.infer.inferExprTy import org.move.lang.core.types.ty.Ty diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MoveModuleDef.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MoveModuleDef.kt index 2dbd44eea..56f779e3e 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MoveModuleDef.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MoveModuleDef.kt @@ -4,10 +4,7 @@ import com.intellij.ide.projectView.PresentationData import com.intellij.lang.ASTNode import com.intellij.navigation.ItemPresentation import com.intellij.openapi.project.Project -import com.intellij.psi.util.CachedValueProvider -import com.intellij.psi.util.CachedValuesManager import com.intellij.psi.util.CachedValuesManager.getProjectPsiDependentCache -import com.intellij.psi.util.PsiModificationTracker import org.move.ide.MoveIcons import org.move.lang.core.psi.* import org.move.lang.core.psi.impl.MvNameIdentifierOwnerImpl @@ -51,39 +48,34 @@ fun MvModule.allNonTestFunctions(): List = allFunctions().filter { ! fun MvModule.testFunctions(): List = allFunctions().filter { it.isTest } fun MvModule.builtinFunctions(): List { - return CachedValuesManager.getManager(this.project).getCachedValue(this) { - val functions = listOf( + return getProjectPsiDependentCache(this) { + listOf( builtinFunction( """ /// Removes `T` from address and returns it. /// Aborts if address does not hold a `T`. native fun move_from(addr: address): T acquires T; - """, project + """, it.project ), builtinFunction( """ /// Publishes `T` under `signer.address`. /// Aborts if `signer.address` already holds a `T`. native fun move_to(acc: &signer, res: T); - """, project + """, it.project ), - builtinFunction("native fun borrow_global(addr: address): &T acquires T;", project), + builtinFunction("native fun borrow_global(addr: address): &T acquires T;", it.project), builtinFunction( "native fun borrow_global_mut(addr: address): &mut T acquires T;", - project + it.project ), builtinFunction( """ /// Returns `true` if a `T` is stored under address native fun exists(addr: address): bool; - """, project + """, it.project ), - builtinFunction("native fun freeze(mut_ref: &mut S): &S;", project), - ) - - CachedValueProvider.Result.create( - functions, - PsiModificationTracker.MODIFICATION_COUNT + builtinFunction("native fun freeze(mut_ref: &mut S): &S;", it.project), ) } } @@ -125,30 +117,29 @@ fun MvModule.structs(): List = moduleBlock?.structList.orEmpty() fun MvModule.schemas(): List = moduleBlock?.schemaList.orEmpty() fun MvModule.builtinSpecFunctions(): List { - return CachedValuesManager.getCachedValue(this) { - val funcs = listOf( - builtinSpecFunction("spec native fun max_u8(): num;", project), - builtinSpecFunction("spec native fun max_u64(): num;", project), - builtinSpecFunction("spec native fun max_u128(): num;", project), - builtinSpecFunction("spec native fun global(addr: address): T;", project), - builtinSpecFunction("spec native fun old(_: T): T;", project), + return getProjectPsiDependentCache(this) { + listOf( + builtinSpecFunction("spec native fun max_u8(): num;", it.project), + builtinSpecFunction("spec native fun max_u64(): num;", it.project), + builtinSpecFunction("spec native fun max_u128(): num;", it.project), + builtinSpecFunction("spec native fun global(addr: address): T;", it.project), + builtinSpecFunction("spec native fun old(_: T): T;", it.project), builtinSpecFunction( "spec native fun update_field(s: S, fname: F, val: V): S;", - project + it.project ), - builtinSpecFunction("spec native fun TRACE(_: T): T;", project), + builtinSpecFunction("spec native fun TRACE(_: T): T;", it.project), // vector functions - builtinSpecFunction("spec native fun len(_: vector): num;", project), + builtinSpecFunction("spec native fun len(_: vector): num;", it.project), builtinSpecFunction( "spec native fun concat(v1: vector, v2: vector): vector;", - project + it.project ), - builtinSpecFunction("spec native fun contains(v: vector, e: T): bool;", project), - builtinSpecFunction("spec native fun index_of(_: vector, _: T): num;", project), - builtinSpecFunction("spec native fun range(_: vector): range;", project), - builtinSpecFunction("spec native fun in_range(_: vector, _: num): bool;", project), + builtinSpecFunction("spec native fun contains(v: vector, e: T): bool;", it.project), + builtinSpecFunction("spec native fun index_of(_: vector, _: T): num;", it.project), + builtinSpecFunction("spec native fun range(_: vector): range;", it.project), + builtinSpecFunction("spec native fun in_range(_: vector, _: num): bool;", it.project), ) - CachedValueProvider.Result(funcs, PsiModificationTracker.MODIFICATION_COUNT) } } diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvCallExpr.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvCallExpr.kt index 35619a153..a9b5f1d15 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvCallExpr.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvCallExpr.kt @@ -1,9 +1,9 @@ package org.move.lang.core.psi.ext -import org.move.lang.core.psi.MvValueArgumentList import org.move.lang.core.psi.MvCallExpr import org.move.lang.core.psi.MvExpr import org.move.lang.core.psi.MvTypeArgument +import org.move.lang.core.psi.MvValueArgumentList import org.move.lang.core.types.infer.InferenceContext import org.move.lang.core.types.infer.inferCallExprTy import org.move.lang.core.types.ty.Ty diff --git a/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt b/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt index b7680dcad..fe0dbae65 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt @@ -70,7 +70,7 @@ fun inferExprTy(expr: MvExpr, parentCtx: InferenceContext, expectedTy: Ty? = nul exprTy = TyNum } if (expectedTy != null) { - if (!isCompatible(expectedTy, exprTy)) { + if (!isCompatible(expectedTy, exprTy, parentCtx.msl)) { parentCtx.typeErrors.add(TypeError.TypeMismatch(expr, expectedTy, exprTy)) } else { parentCtx.addConstraint(exprTy, expectedTy) @@ -335,7 +335,7 @@ private fun inferIfExprTy(ifExpr: MvIfExpr, ctx: InferenceContext, expectedTy: T else -> return TyUnknown } - return combineTys(ifExprTy, elseExprTy) + return combineTys(ifExprTy, elseExprTy, ctx.msl) } private fun inferWhileExprTy(whileExpr: MvWhileExpr, ctx: InferenceContext): Ty { diff --git a/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt b/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt index fc8be3fde..afd93306e 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt @@ -3,9 +3,7 @@ package org.move.lang.core.types.infer import com.intellij.openapi.util.Key import com.intellij.psi.PsiElement import com.intellij.psi.util.CachedValue -import com.intellij.psi.util.CachedValueProvider -import com.intellij.psi.util.CachedValuesManager -import com.intellij.psi.util.PsiModificationTracker +import com.intellij.psi.util.CachedValuesManager.getProjectPsiDependentCache import com.jetbrains.rd.util.concurrentMapOf import org.move.ide.presentation.expectedBindingFormText import org.move.ide.presentation.name @@ -22,18 +20,26 @@ fun MvElement.functionInferenceCtx(msl: Boolean = this.isMsl()): InferenceContex } fun MvFunctionLike.inferenceCtx(msl: Boolean): InferenceContext { - val ctx = CachedValuesManager.getCachedValue(this, TYPE_INFERENCE_KEY) { - val functionCtx = InferenceContext(msl) - for (param in this.parameterBindings) { - functionCtx.bindingTypes[param] = param.inferredTy(functionCtx) + return if (msl) { + getProjectPsiDependentCache(this) { + getInferenceContext(it, true) } - if (this is MvFunction) { - this.codeBlock?.let { inferCodeBlockTy(it, functionCtx, this.returnTy) } + } else { + getProjectPsiDependentCache(this) { + getInferenceContext(it, false) } - CachedValueProvider.Result(functionCtx, PsiModificationTracker.MODIFICATION_COUNT) } - ctx.msl = msl - return ctx +} + +private fun getInferenceContext(owner: MvFunctionLike, msl: Boolean): InferenceContext { + val functionCtx = InferenceContext(msl) + for (param in owner.parameterBindings) { + functionCtx.bindingTypes[param] = param.inferredTy(functionCtx) + } + if (owner is MvFunction) { + owner.codeBlock?.let { inferCodeBlockTy(it, functionCtx, owner.returnTy) } + } + return functionCtx } fun inferCodeBlockTy(block: MvCodeBlock, blockCtx: InferenceContext, expectedTy: Ty?): Ty { @@ -141,7 +147,7 @@ fun isCompatibleStructs(expectedTy: TyStruct, inferredTy: TyStruct, msl: Boolean fun isCompatibleTuples(expectedTy: TyTuple, inferredTy: TyTuple, msl: Boolean): Boolean { return expectedTy.types.size == inferredTy.types.size - && expectedTy.types.zip(inferredTy.types).all { isCompatible(it.first, it.second) } + && expectedTy.types.zip(inferredTy.types).all { isCompatible(it.first, it.second, msl) } } fun isCompatibleIntegers(expectedTy: TyInteger, inferredTy: TyInteger): Boolean { @@ -151,11 +157,11 @@ fun isCompatibleIntegers(expectedTy: TyInteger, inferredTy: TyInteger): Boolean } /// find common denominator for both types -fun combineTys(ty1: Ty, ty2: Ty): Ty { - if (!isCompatible(ty1, ty2) && !isCompatible(ty2, ty1)) return TyUnknown +fun combineTys(ty1: Ty, ty2: Ty, msl: Boolean): Ty { + if (!isCompatible(ty1, ty2, msl) && !isCompatible(ty2, ty1, msl)) return TyUnknown return when { ty1 is TyReference && ty2 is TyReference - && isCompatible(ty1.referenced, ty2.referenced) -> { + && isCompatible(ty1.referenced, ty2.referenced, msl) -> { val combined = ty1.permissions.intersect(ty2.permissions) TyReference(ty1.referenced, combined, ty1.msl || ty2.msl) } diff --git a/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt b/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt index 803daa8aa..310bf7479 100644 --- a/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt @@ -740,4 +740,32 @@ module 0x1::M { } """) + fun `test no error integer should ignore spec blocks`() = checkErrors(""" + module 0x1::main { + spec fun spec_pow(y: u64, x: u64): u64 { + if (x == 0) { + 1 + } else { + y * spec_pow(y, x - 1) + } + } + + /// Returns 10^degree. + public fun pow_10(degree: u8): u64 { + let res = 1; + let i = 0; + while ({ + spec { + invariant res == spec_pow(10, i); + invariant 0 <= i && i <= degree; + }; + i < degree + }) { + res = res * 10; + i = i + 1; + }; + res + } + } + """) } diff --git a/src/test/kotlin/org/move/lang/types/ExpressionTypesTest.kt b/src/test/kotlin/org/move/lang/types/ExpressionTypesTest.kt index 69b34b849..67018a90a 100644 --- a/src/test/kotlin/org/move/lang/types/ExpressionTypesTest.kt +++ b/src/test/kotlin/org/move/lang/types/ExpressionTypesTest.kt @@ -498,4 +498,33 @@ class ExpressionTypesTest: TypificationTestCase() { } } """) + + fun `test integer inference with spec blocks inside block`() = testExpr(""" + module 0x1::main { + spec fun get_num(): num { 1 } + fun main() { + let myint = 1; + myint + 1u8; + spec { + myint + //^ num + }; + } + } + """) + + fun `test integer inference with spec blocks outside block`() = testExpr(""" + module 0x1::main { + spec fun get_num(): num { 1 } + fun main() { + let myint = 1; + myint + 1u8; + spec { + myint + get_num(); + }; + myint; + //^ u8 + } + } + """) } From d8328425a439d8f7d678e1dd8a1a421f7def0163 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Thu, 15 Sep 2022 21:40:04 +0200 Subject: [PATCH 07/26] lots of stuff --- changelog/1.20.0.md | 4 + gradle-222.properties | 2 +- gradle.properties | 2 +- src/main/grammars/MoveParser.bnf | 2 +- ...{ErrorAnnotator.kt => MvErrorAnnotator.kt} | 2 +- .../ide/inspections/MvLocalInspectionTool.kt | 2 + .../ide/inspections/MvTypeCheckInspection.kt | 7 +- .../inspections/MvUnusedVariableInspection.kt | 26 +- .../inspections/fixes/RemoveParameterFix.kt | 48 +++ .../move/ide/inspections/fixes/RenameFix.kt | 36 ++ .../move/ide/intentions/ChopListIntention.kt | 5 +- .../org/move/lang/core/psi/MvElement.kt | 45 +- .../org/move/lang/core/psi/MvNamedElement.kt | 2 +- .../org/move/lang/core/psi/MvPsiFactory.kt | 7 + .../org/move/lang/core/psi/ext/MvCallExpr.kt | 4 + .../org/move/lang/core/psi/ext/MvFunction.kt | 1 + .../lang/core/types/infer/InferenceContext.kt | 32 ++ .../org/move/lang/index/MvModuleSpecIndex.kt | 14 +- .../move/lang/index/MvNamedElementIndex.kt | 4 +- src/main/kotlin/org/move/openapiext/utils.kt | 34 ++ .../tests/annotation/AnnotatorTestCase.kt | 13 + src/main/resources/META-INF/plugin.xml | 4 +- .../errors/BuiltInFunctionNameErrorTest.kt | 4 +- .../annotator/errors/BuiltinCallErrorTest.kt | 4 +- .../errors/DuplicateMembersErrorTest.kt | 4 +- .../errors/ParametersNumberErrorTest.kt | 4 +- .../errors/StructFieldsNumberErrorTest.kt | 4 +- .../errors/TypeParametersNumberErrorTest.kt | 4 +- .../inspections/MvTypeCheckInspectionTest.kt | 393 ++++++++++++------ .../MvUnusedVariableInspectionTest.kt | 38 +- .../RedundantQualifiedPathInspectionTest.kt | 27 ++ .../fixes/RemoveParameterFixTest.kt | 140 +++++++ .../ChopValueArgumentListIntentionTest.kt | 25 ++ .../lang/parser/complete/expressions.move | 2 + .../move/lang/parser/complete/expressions.txt | 23 + 35 files changed, 788 insertions(+), 180 deletions(-) rename src/main/kotlin/org/move/ide/annotator/{ErrorAnnotator.kt => MvErrorAnnotator.kt} (99%) create mode 100644 src/main/kotlin/org/move/ide/inspections/fixes/RemoveParameterFix.kt create mode 100644 src/main/kotlin/org/move/ide/inspections/fixes/RenameFix.kt create mode 100644 src/test/kotlin/org/move/ide/inspections/fixes/RemoveParameterFixTest.kt create mode 100644 src/test/kotlin/org/move/ide/intentions/ChopValueArgumentListIntentionTest.kt diff --git a/changelog/1.20.0.md b/changelog/1.20.0.md index 9308268a1..ab31778c1 100644 --- a/changelog/1.20.0.md +++ b/changelog/1.20.0.md @@ -4,6 +4,10 @@ TBD ## New Features +* Remove parameter quickfix + +TODO: gif + * Highlight hex integer literals TODO: screenshot diff --git a/gradle-222.properties b/gradle-222.properties index 53a91b47f..b2323b465 100644 --- a/gradle-222.properties +++ b/gradle-222.properties @@ -9,5 +9,5 @@ platformVersion = 2022.2 # Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html # Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22 -platformPlugins = org.toml.lang:222.3345.108 +platformPlugins = org.toml.lang verifierIdeVersions = IC-2022.2 diff --git a/gradle.properties b/gradle.properties index 163aa24eb..eba3e1e23 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,4 +14,4 @@ propertiesPluginEnvironmentNameProperty=shortPlatformVersion # properties files # supported versions are 212, 213, 221, 222, default is 212 # pass ORG_GRADLE_PROJECT_shortPlatformVersion environment variable to overwrite -shortPlatformVersion=222 +shortPlatformVersion=212 diff --git a/src/main/grammars/MoveParser.bnf b/src/main/grammars/MoveParser.bnf index c02082b3a..07356c06d 100644 --- a/src/main/grammars/MoveParser.bnf +++ b/src/main/grammars/MoveParser.bnf @@ -737,6 +737,7 @@ Expr ::= AssignmentExpr | SpecVisRestrictedExpr | RangeExpr | (ForallQuantExpr | ExistsQuantExpr | ChooseQuantExpr) + | CastExpr | ImplyOperatorsExpr_items | OrExpr | AndExpr @@ -748,7 +749,6 @@ Expr ::= AssignmentExpr | AddExprItem | MulExprItem | ControlFlowExpr - | CastExpr | UnaryExpr | BorrowExpr | AtomExpr diff --git a/src/main/kotlin/org/move/ide/annotator/ErrorAnnotator.kt b/src/main/kotlin/org/move/ide/annotator/MvErrorAnnotator.kt similarity index 99% rename from src/main/kotlin/org/move/ide/annotator/ErrorAnnotator.kt rename to src/main/kotlin/org/move/ide/annotator/MvErrorAnnotator.kt index d858bfe3a..9dfdffefc 100644 --- a/src/main/kotlin/org/move/ide/annotator/ErrorAnnotator.kt +++ b/src/main/kotlin/org/move/ide/annotator/MvErrorAnnotator.kt @@ -14,7 +14,7 @@ import org.move.lang.moveProject import org.move.lang.utils.MvDiagnostic import org.move.lang.utils.addToHolder -class ErrorAnnotator : MvAnnotator() { +class MvErrorAnnotator : MvAnnotator() { override fun annotateInternal(element: PsiElement, holder: AnnotationHolder) { val moveHolder = MvAnnotationHolder(holder) val visitor = object : MvVisitor() { diff --git a/src/main/kotlin/org/move/ide/inspections/MvLocalInspectionTool.kt b/src/main/kotlin/org/move/ide/inspections/MvLocalInspectionTool.kt index d4c998867..3f2bf89e0 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvLocalInspectionTool.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvLocalInspectionTool.kt @@ -3,7 +3,9 @@ package org.move.ide.inspections import com.intellij.codeInspection.LocalInspectionTool import com.intellij.codeInspection.LocalInspectionToolSession import com.intellij.codeInspection.LocalQuickFix +import com.intellij.codeInspection.LocalQuickFixOnPsiElement import com.intellij.codeInspection.ProblemsHolder +import com.intellij.psi.PsiElement import com.intellij.psi.PsiElementVisitor import org.move.cli.moveProjects import org.move.lang.MoveFile diff --git a/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt b/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt index 7fa6d465b..0310cc433 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt @@ -22,7 +22,12 @@ fun ProblemsHolder.registerTypeError( } fun ProblemsHolder.registerTypeError(typeError: TypeError) { - this.registerProblem(typeError.element, typeError.message(), ProblemHighlightType.GENERIC_ERROR) + this.registerProblem( + typeError.element, + typeError.message(), + ProblemHighlightType.GENERIC_ERROR, + typeError.quickfix() + ) } class MvTypeCheckInspection : MvLocalInspectionTool() { diff --git a/src/main/kotlin/org/move/ide/inspections/MvUnusedVariableInspection.kt b/src/main/kotlin/org/move/ide/inspections/MvUnusedVariableInspection.kt index 937390ebd..307a64a86 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvUnusedVariableInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvUnusedVariableInspection.kt @@ -6,7 +6,10 @@ import com.intellij.codeInspection.ProblemHighlightType import com.intellij.codeInspection.ProblemsHolder import com.intellij.openapi.project.Project import com.intellij.psi.util.descendantsOfType +import org.move.ide.inspections.fixes.RemoveParameterFix +import org.move.ide.inspections.fixes.RenameFix import org.move.lang.core.psi.* +import org.move.lang.core.psi.ext.owner class MvUnusedVariableInspection : MvLocalInspectionTool() { override fun buildMvVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) = @@ -27,24 +30,23 @@ class MvUnusedVariableInspection : MvLocalInspectionTool() { val bindingName = binding.name ?: return if (bindingName.startsWith("_")) return - val usages = binding.usages() + val references = binding.searchReferences() // filter out #[test] attributes .filter { it.element !is MvAttrItemArgument } - if (usages.none()) { + if (references.none()) { + val fixes = when (binding.owner) { + is MvFunctionParameter -> arrayOf( + RenameFix(binding, "_$bindingName"), + RemoveParameterFix(binding, bindingName) + ) + else -> arrayOf(RenameFix(binding, "_$bindingName")) + } holder.registerProblem( binding, description, ProblemHighlightType.LIKE_UNUSED_SYMBOL, - object : LocalQuickFix { - override fun getFamilyName(): String { - return "Rename to _$bindingName" - } - - override fun applyFix(project: Project, descriptor: ProblemDescriptor) { - val bindingPat = descriptor.psiElement as MvBindingPat - bindingPat.rename("_$bindingName") - } - }) + *fixes + ) } } } diff --git a/src/main/kotlin/org/move/ide/inspections/fixes/RemoveParameterFix.kt b/src/main/kotlin/org/move/ide/inspections/fixes/RemoveParameterFix.kt new file mode 100644 index 000000000..abd2600c5 --- /dev/null +++ b/src/main/kotlin/org/move/ide/inspections/fixes/RemoveParameterFix.kt @@ -0,0 +1,48 @@ +package org.move.ide.inspections.fixes + +import com.intellij.codeInspection.LocalQuickFixOnPsiElement +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiFile +import com.intellij.psi.util.parentOfType +import org.move.lang.core.psi.* +import org.move.lang.core.psi.ext.callArgumentExprs +import org.move.lang.core.psi.ext.valueArguments + +/** + * Fix that removes a parameter and all its usages at call sites. + */ +class RemoveParameterFix( + binding: MvBindingPat, + private val bindingName: String +) : LocalQuickFixOnPsiElement(binding) { + override fun getText() = "Remove parameter `$bindingName`" + override fun getFamilyName() = "Remove parameter" + + override fun invoke(project: Project, file: PsiFile, startElement: PsiElement, endElement: PsiElement) { + val binding = startElement as? MvBindingPat ?: return + val parameter = binding.parent as? MvFunctionParameter ?: return + val function = parameter.parentOfType() ?: return + + val parameterIndex = function.parameters.indexOf(parameter) + if (parameterIndex == -1) return + + parameter.deleteWithSurroundingCommaAndWhitespace() + removeArguments(function, parameterIndex) + } +} + +private fun removeArguments(function: MvFunction, parameterIndex: Int) { + val calls = function.searchReferences() + .asSequence() + .mapNotNull { + val path = it.element + val pathExpr = path.parent + pathExpr as? MvCallExpr + } + calls.forEach { call -> + call.valueArguments + .getOrNull(parameterIndex) + ?.deleteWithSurroundingCommaAndWhitespace() + } +} diff --git a/src/main/kotlin/org/move/ide/inspections/fixes/RenameFix.kt b/src/main/kotlin/org/move/ide/inspections/fixes/RenameFix.kt new file mode 100644 index 000000000..740923070 --- /dev/null +++ b/src/main/kotlin/org/move/ide/inspections/fixes/RenameFix.kt @@ -0,0 +1,36 @@ +/* + * Use of this source code is governed by the MIT license that can be + * found in the LICENSE file. + */ + +package org.move.ide.inspections.fixes + +import com.intellij.codeInspection.LocalQuickFixOnPsiElement +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiFile +import com.intellij.psi.PsiNamedElement +import com.intellij.refactoring.RefactoringFactory +import org.move.openapiext.nonBlocking + +/** + * Fix that renames the given element. + * @param element The element to be renamed. + * @param newName The new name for the element. + * @param fixName The name to use for the fix instead of the default one to better fit the inspection. + */ +class RenameFix( + element: PsiNamedElement, + val newName: String, + private val fixName: String = "Rename to $newName" +) : LocalQuickFixOnPsiElement(element) { + override fun getText() = fixName + override fun getFamilyName() = "Rename element" + + override fun invoke(project: Project, file: PsiFile, startElement: PsiElement, endElement: PsiElement) = + project.nonBlocking( + { startElement }, + { + RefactoringFactory.getInstance(project).createRename(it, newName).run() + }) +} diff --git a/src/main/kotlin/org/move/ide/intentions/ChopListIntention.kt b/src/main/kotlin/org/move/ide/intentions/ChopListIntention.kt index a455e083d..7d87e4dfd 100644 --- a/src/main/kotlin/org/move/ide/intentions/ChopListIntention.kt +++ b/src/main/kotlin/org/move/ide/intentions/ChopListIntention.kt @@ -14,6 +14,7 @@ abstract class ChopListIntentionBase( elementClass: Class, @IntentionName intentionText: String ) : ListIntentionBase(listClass, elementClass, intentionText) { + override fun findApplicableContext(project: Project, editor: Editor, element: PsiElement): TList? { val list = element.listContext ?: return null val elements = getElements(list) @@ -53,9 +54,9 @@ class ChopParameterListIntention : ChopListIntentionBase( +class ChopValueArgumentListIntention : ChopListIntentionBase( MvValueArgumentList::class.java, - MvExpr::class.java, + MvValueArgument::class.java, "Put arguments on separate lines" ) diff --git a/src/main/kotlin/org/move/lang/core/psi/MvElement.kt b/src/main/kotlin/org/move/lang/core/psi/MvElement.kt index 7e0bcd77f..77dce4370 100644 --- a/src/main/kotlin/org/move/lang/core/psi/MvElement.kt +++ b/src/main/kotlin/org/move/lang/core/psi/MvElement.kt @@ -2,12 +2,12 @@ package org.move.lang.core.psi import com.intellij.extapi.psi.ASTWrapperPsiElement import com.intellij.lang.ASTNode +import com.intellij.psi.PsiComment import com.intellij.psi.PsiElement +import com.intellij.psi.PsiWhiteSpace import org.move.lang.MoveFile -import org.move.lang.core.psi.ext.ancestorOrSelf -import org.move.lang.core.psi.ext.ancestorStrict -import org.move.lang.core.psi.ext.findFirstParent -import org.move.lang.core.psi.ext.module +import org.move.lang.MvElementTypes +import org.move.lang.core.psi.ext.* interface MvElement : PsiElement @@ -43,3 +43,40 @@ val MvElement.containingModuleOrScript: MvElement? return this.findFirstParent(false) { it is MvScript || it is MvModule } as? MvElement } + +/** + * Delete the element along with a neighbour comma. + * If a comma follows the element, it will be deleted. + * Else if a comma precedes the element, it will be deleted. + * + * It is useful to remove elements that are parts of comma separated lists (parameters, arguments, use specks, ...). + */ +fun MvElement.deleteWithSurroundingComma() { + val followingComma = getNextNonCommentSibling() + if (followingComma?.elementType == MvElementTypes.COMMA) { + followingComma?.delete() + } else { + val precedingComma = getPrevNonCommentSibling() + if (precedingComma?.elementType == MvElementTypes.COMMA) { + precedingComma?.delete() + } + } + + delete() +} + +/** + * Delete the element along with all surrounding whitespace and a single surrounding comma. + * See [deleteWithSurroundingComma]. + */ +fun MvElement.deleteWithSurroundingCommaAndWhitespace() { + val toDelete = rightSiblings.takeWhile { it.isWhitespaceOrComment } + + leftSiblings.takeWhile { it.isWhitespaceOrComment } + toDelete.forEach { + it.delete() + } + deleteWithSurroundingComma() +} + +private val PsiElement.isWhitespaceOrComment + get(): Boolean = this is PsiWhiteSpace || this is PsiComment diff --git a/src/main/kotlin/org/move/lang/core/psi/MvNamedElement.kt b/src/main/kotlin/org/move/lang/core/psi/MvNamedElement.kt index 9c654be64..c9aef18c2 100644 --- a/src/main/kotlin/org/move/lang/core/psi/MvNamedElement.kt +++ b/src/main/kotlin/org/move/lang/core/psi/MvNamedElement.kt @@ -62,7 +62,7 @@ val MvNamedElement.completionPriority else -> LOCAL_ITEM_PRIORITY } -fun MvNamedElement.usages(): Query = +fun MvNamedElement.searchReferences(): Query = ReferencesSearch.search( this, PsiSearchHelper.getInstance(this.project).getUseScope(this) diff --git a/src/main/kotlin/org/move/lang/core/psi/MvPsiFactory.kt b/src/main/kotlin/org/move/lang/core/psi/MvPsiFactory.kt index f5395f5a9..7802a2f1d 100644 --- a/src/main/kotlin/org/move/lang/core/psi/MvPsiFactory.kt +++ b/src/main/kotlin/org/move/lang/core/psi/MvPsiFactory.kt @@ -26,6 +26,13 @@ class MvPsiFactory(private val project: Project) { fun inlineModule(address: String, name: String, blockText: String): MvModule = createFromText("module $address::$name $blockText") ?: error("failed to create module") + fun abilitiesList(names: List): MvAbilitiesList = + createFromText("module 0x1::main { struct S has ${names.joinToString(", ")} {} }") + ?: error("failed to create abilities") + + fun ability(name: String): MvAbility = + createFromText("module 0x1::main { struct S has $name {} }") ?: error("failed to create ability") + fun identifier(text: String): PsiElement = createFromText("module $text {}")?.nameIdentifier ?: error("Failed to create identifier: `$text`") diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvCallExpr.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvCallExpr.kt index a9b5f1d15..fb641fbfd 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvCallExpr.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvCallExpr.kt @@ -3,6 +3,7 @@ package org.move.lang.core.psi.ext import org.move.lang.core.psi.MvCallExpr import org.move.lang.core.psi.MvExpr import org.move.lang.core.psi.MvTypeArgument +import org.move.lang.core.psi.MvValueArgument import org.move.lang.core.psi.MvValueArgumentList import org.move.lang.core.types.infer.InferenceContext import org.move.lang.core.types.infer.inferCallExprTy @@ -11,6 +12,9 @@ import org.move.lang.core.types.ty.TyFunction val MvCallExpr.typeArguments: List get() = this.path.typeArguments +val MvCallExpr.valueArguments: List get() = + this.valueArgumentList?.valueArgumentList.orEmpty() + val MvCallExpr.callArgumentExprs: List get() = this.valueArgumentList ?.valueArgumentList.orEmpty().map { it.expr } diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvFunction.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvFunction.kt index 502c1538f..aa011fd6b 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvFunction.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvFunction.kt @@ -4,6 +4,7 @@ import com.intellij.ide.projectView.PresentationData import com.intellij.lang.ASTNode import com.intellij.navigation.ItemPresentation import com.intellij.openapi.editor.colors.TextAttributesKey +import com.intellij.psi.PsiReference import com.intellij.psi.util.CachedValuesManager.getProjectPsiDependentCache import com.intellij.util.PlatformIcons import org.move.ide.MoveIcons diff --git a/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt b/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt index afd93306e..5b25d7b64 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt @@ -1,13 +1,18 @@ package org.move.lang.core.types.infer +import com.intellij.codeInspection.LocalQuickFix +import com.intellij.codeInspection.ProblemDescriptor +import com.intellij.openapi.project.Project import com.intellij.openapi.util.Key import com.intellij.psi.PsiElement import com.intellij.psi.util.CachedValue import com.intellij.psi.util.CachedValuesManager.getProjectPsiDependentCache import com.jetbrains.rd.util.concurrentMapOf +import org.move.ide.inspections.InspectionQuickFix import org.move.ide.presentation.expectedBindingFormText import org.move.ide.presentation.name import org.move.ide.presentation.text +import org.move.lang.MvElementTypes.SEMICOLON import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.* import org.move.lang.core.psi.mixins.ty @@ -235,6 +240,7 @@ fun isCompatibleAbilities(expectedTy: Ty, actualTy: Ty, msl: Boolean): Compat { sealed class TypeError(open val element: PsiElement) { abstract fun message(): String + open fun quickfix(): LocalQuickFix? = null data class TypeMismatch( override val element: PsiElement, @@ -259,6 +265,32 @@ sealed class TypeError(open val element: PsiElement) { "does not have required ability '${abilities.map { it.label() }.first()}'" } + override fun quickfix(): LocalQuickFix? { + if (abilities.size > 1) return null + val abilityName = abilities.map { it.label() }.first() + return object : InspectionQuickFix("Add '$abilityName' ability to ${ty.name()}") { + override fun applyFix(project: Project, descriptor: ProblemDescriptor) { + val pathType = descriptor.psiElement as? MvPathType ?: return + val struct = pathType.reference?.resolve() as? MvStruct ?: return + // sanity check + val existingAbilities = struct.abilities.map { it.text } + if (abilityName in existingAbilities) return + + val newList = project.psiFactory.abilitiesList(existingAbilities + listOf(abilityName)) + if (struct.abilitiesList != null) { + struct.abilitiesList?.replace(newList) + } else { + val anchor = when { + struct.structBlock != null -> struct.structBlock + struct.hasChild(SEMICOLON) -> struct.getChild(SEMICOLON) + else -> return + } + struct.addBefore(newList, anchor) + } + struct.abilitiesList?.replace(newList) + } + } + } } data class UnsupportedBinaryOp( diff --git a/src/main/kotlin/org/move/lang/index/MvModuleSpecIndex.kt b/src/main/kotlin/org/move/lang/index/MvModuleSpecIndex.kt index 54221fae4..d0176d1b9 100644 --- a/src/main/kotlin/org/move/lang/index/MvModuleSpecIndex.kt +++ b/src/main/kotlin/org/move/lang/index/MvModuleSpecIndex.kt @@ -18,8 +18,8 @@ class MvModuleSpecIndex : BaseMoveFileIndex() { override fun getName() = KEY override fun getVersion() = INDEX_VERSION override fun getIndexer() = - DataIndexer { data -> - val file = data.psiFile as? MoveFile ?: return@DataIndexer emptyMap() + DataIndexer { fileContent -> + val file = fileContent.psiFile as? MoveFile ?: return@DataIndexer emptyMap() // create (moduleName -> null) map for every file file.moduleSpecs() .mapNotNull { it.fqModuleRef?.referenceName } @@ -35,9 +35,9 @@ class MvModuleSpecIndex : BaseMoveFileIndex() { FileBasedIndex.getInstance().requestRebuild(KEY) } - fun getAllKeys(project: Project): Collection { - return FileBasedIndex.getInstance().getAllKeys(MvNamedElementIndex.KEY, project) - } +// fun getAllKeys(project: Project): Collection { +// return FileBasedIndex.getInstance().getAllKeys(MvNamedElementIndex.KEY, project) +// } fun moduleSpecFiles( project: Project, @@ -50,10 +50,8 @@ class MvModuleSpecIndex : BaseMoveFileIndex() { return listOf(moduleFile) } } - val moduleName = module.name ?: return emptyList() - val fileIndex = FileBasedIndex.getInstance() - return fileIndex + return FileBasedIndex.getInstance() .getContainingFiles(KEY, moduleName, searchScope) .mapNotNull { it.toMoveFile(project) } .toList() diff --git a/src/main/kotlin/org/move/lang/index/MvNamedElementIndex.kt b/src/main/kotlin/org/move/lang/index/MvNamedElementIndex.kt index 3b54f5fb4..3feccfeb6 100644 --- a/src/main/kotlin/org/move/lang/index/MvNamedElementIndex.kt +++ b/src/main/kotlin/org/move/lang/index/MvNamedElementIndex.kt @@ -15,8 +15,8 @@ class MvNamedElementIndex : BaseMoveFileIndex() { override fun getName() = KEY override fun getVersion() = INDEX_VERSION override fun getIndexer() = - DataIndexer { data -> - val file = data.psiFile as? MoveFile ?: return@DataIndexer emptyMap() + DataIndexer { fileContent -> + val file = fileContent.psiFile as? MoveFile ?: return@DataIndexer emptyMap() val map = file .descendantsOfType() .mapNotNull { it.name } diff --git a/src/main/kotlin/org/move/openapiext/utils.kt b/src/main/kotlin/org/move/openapiext/utils.kt index cb695497a..4a02e9d73 100644 --- a/src/main/kotlin/org/move/openapiext/utils.kt +++ b/src/main/kotlin/org/move/openapiext/utils.kt @@ -5,11 +5,16 @@ package org.move.openapiext +import com.intellij.openapi.Disposable import com.intellij.openapi.actionSystem.CommonDataKeys import com.intellij.openapi.actionSystem.DataContext import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.Experiments +import com.intellij.openapi.application.ModalityState +import com.intellij.openapi.application.ReadAction import com.intellij.openapi.command.WriteCommandAction +import com.intellij.openapi.components.Service +import com.intellij.openapi.components.service import com.intellij.openapi.editor.Document import com.intellij.openapi.editor.Editor import com.intellij.openapi.fileEditor.FileDocumentManager @@ -27,12 +32,14 @@ import com.intellij.psi.PsiDirectory import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiFile import com.intellij.psi.PsiManager +import com.intellij.util.concurrency.AppExecutorUtil import org.jdom.Element import org.move.lang.toNioPathOrNull import org.move.openapiext.common.isHeadlessEnvironment import org.move.openapiext.common.isUnitTestMode import java.nio.file.Path import java.nio.file.Paths +import java.util.concurrent.Callable fun Project.runWriteCommandAction(command: () -> T): T { return WriteCommandAction.runWriteCommandAction(this, Computable { command() }) @@ -142,3 +149,30 @@ fun isFeatureEnabled(featureId: String): Boolean { return Experiments.getInstance().isFeatureEnabled(featureId) } + +/** Intended to be invoked from EDT */ +inline fun Project.nonBlocking(crossinline block: () -> R, crossinline uiContinuation: (R) -> Unit) { + if (isUnitTestMode) { + val result = block() + uiContinuation(result) + } else { + ReadAction.nonBlocking(Callable { + block() + }) + .inSmartMode(this) + .expireWith(MvPluginDisposable.getInstance(this)) + .finishOnUiThread(ModalityState.current()) { result -> + uiContinuation(result) + }.submit(AppExecutorUtil.getAppExecutorService()) + } +} + +@Service +class MvPluginDisposable : Disposable { + companion object { + @JvmStatic + fun getInstance(project: Project): Disposable = project.service() + } + + override fun dispose() {} +} diff --git a/src/main/kotlin/org/move/utils/tests/annotation/AnnotatorTestCase.kt b/src/main/kotlin/org/move/utils/tests/annotation/AnnotatorTestCase.kt index 43f8624ac..2bdc6db1f 100644 --- a/src/main/kotlin/org/move/utils/tests/annotation/AnnotatorTestCase.kt +++ b/src/main/kotlin/org/move/utils/tests/annotation/AnnotatorTestCase.kt @@ -5,7 +5,10 @@ package org.move.utils.tests.annotation +import com.intellij.psi.PsiFile +import org.intellij.lang.annotations.Language import org.move.ide.annotator.MvAnnotator +import org.move.utils.tests.replaceCaretMarker import kotlin.reflect.KClass abstract class AnnotatorTestCase( @@ -15,4 +18,14 @@ abstract class AnnotatorTestCase( override fun createAnnotationFixture(): MvAnnotationTestFixture = MvAnnotationTestFixture( this, myFixture, annotatorClasses = listOf(annotatorClass) ) + + protected fun checkFixByText( + fixName: String, + @Language("Move") before: String, + @Language("Move") after: String, + checkWarn: Boolean = true, + checkInfo: Boolean = false, + checkWeakWarn: Boolean = false, + ) = + annotationFixture.checkFixByText(fixName, before, after, checkWarn, checkInfo, checkWeakWarn) } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index bfda24428..272d91cbc 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -108,7 +108,7 @@ implementation="org.move.toml.NamedAddressReferenceContributor"/> + implementationClass="org.move.ide.annotator.MvErrorAnnotator"/> @@ -270,7 +270,7 @@ Move - org.move.ide.intentions.ChopArgumentListIntention + org.move.ide.intentions.ChopValueArgumentListIntention Move diff --git a/src/test/kotlin/org/move/ide/annotator/errors/BuiltInFunctionNameErrorTest.kt b/src/test/kotlin/org/move/ide/annotator/errors/BuiltInFunctionNameErrorTest.kt index e1c66af23..9f42d5b58 100644 --- a/src/test/kotlin/org/move/ide/annotator/errors/BuiltInFunctionNameErrorTest.kt +++ b/src/test/kotlin/org/move/ide/annotator/errors/BuiltInFunctionNameErrorTest.kt @@ -1,9 +1,9 @@ package org.move.ide.annotator.errors -import org.move.ide.annotator.ErrorAnnotator +import org.move.ide.annotator.MvErrorAnnotator import org.move.utils.tests.annotation.AnnotatorTestCase -class BuiltInFunctionNameErrorTest: AnnotatorTestCase(ErrorAnnotator::class) { +class BuiltInFunctionNameErrorTest: AnnotatorTestCase(MvErrorAnnotator::class) { fun `test function`() = checkErrors(""" module 0x1::M { fun move_to() {} diff --git a/src/test/kotlin/org/move/ide/annotator/errors/BuiltinCallErrorTest.kt b/src/test/kotlin/org/move/ide/annotator/errors/BuiltinCallErrorTest.kt index 8cf9fabcb..d5fa13007 100644 --- a/src/test/kotlin/org/move/ide/annotator/errors/BuiltinCallErrorTest.kt +++ b/src/test/kotlin/org/move/ide/annotator/errors/BuiltinCallErrorTest.kt @@ -1,9 +1,9 @@ package org.move.ide.annotator.errors -import org.move.ide.annotator.ErrorAnnotator +import org.move.ide.annotator.MvErrorAnnotator import org.move.utils.tests.annotation.AnnotatorTestCase -class BuiltinCallErrorTest: AnnotatorTestCase(ErrorAnnotator::class) { +class BuiltinCallErrorTest: AnnotatorTestCase(MvErrorAnnotator::class) { fun `test builtin resource functions can only be called with struct from the current module`() = checkErrors(""" module 0x1::M { struct S1 has key {} diff --git a/src/test/kotlin/org/move/ide/annotator/errors/DuplicateMembersErrorTest.kt b/src/test/kotlin/org/move/ide/annotator/errors/DuplicateMembersErrorTest.kt index 0234c4bd8..69d979016 100644 --- a/src/test/kotlin/org/move/ide/annotator/errors/DuplicateMembersErrorTest.kt +++ b/src/test/kotlin/org/move/ide/annotator/errors/DuplicateMembersErrorTest.kt @@ -1,9 +1,9 @@ package org.move.ide.annotator.errors -import org.move.ide.annotator.ErrorAnnotator +import org.move.ide.annotator.MvErrorAnnotator import org.move.utils.tests.annotation.AnnotatorTestCase -class DuplicateMembersErrorTest : AnnotatorTestCase(ErrorAnnotator::class) { +class DuplicateMembersErrorTest : AnnotatorTestCase(MvErrorAnnotator::class) { fun `test duplicate function in script`() = checkErrors( """ script { diff --git a/src/test/kotlin/org/move/ide/annotator/errors/ParametersNumberErrorTest.kt b/src/test/kotlin/org/move/ide/annotator/errors/ParametersNumberErrorTest.kt index 7554349e5..9b8b0db02 100644 --- a/src/test/kotlin/org/move/ide/annotator/errors/ParametersNumberErrorTest.kt +++ b/src/test/kotlin/org/move/ide/annotator/errors/ParametersNumberErrorTest.kt @@ -1,9 +1,9 @@ package org.move.ide.annotator.errors -import org.move.ide.annotator.ErrorAnnotator +import org.move.ide.annotator.MvErrorAnnotator import org.move.utils.tests.annotation.AnnotatorTestCase -class ParametersNumberErrorTest: AnnotatorTestCase(ErrorAnnotator::class) { +class ParametersNumberErrorTest: AnnotatorTestCase(MvErrorAnnotator::class) { fun `test valid number of parameters`() = checkErrors(""" module 0x1::M { fun params_0() {} diff --git a/src/test/kotlin/org/move/ide/annotator/errors/StructFieldsNumberErrorTest.kt b/src/test/kotlin/org/move/ide/annotator/errors/StructFieldsNumberErrorTest.kt index 78bf12367..88f89491d 100644 --- a/src/test/kotlin/org/move/ide/annotator/errors/StructFieldsNumberErrorTest.kt +++ b/src/test/kotlin/org/move/ide/annotator/errors/StructFieldsNumberErrorTest.kt @@ -1,9 +1,9 @@ package org.move.ide.annotator.errors -import org.move.ide.annotator.ErrorAnnotator +import org.move.ide.annotator.MvErrorAnnotator import org.move.utils.tests.annotation.AnnotatorTestCase -class StructFieldsNumberErrorTest: AnnotatorTestCase(ErrorAnnotator::class) { +class StructFieldsNumberErrorTest: AnnotatorTestCase(MvErrorAnnotator::class) { fun `test missing fields for struct`() = checkErrors(""" module 0x1::M { struct T { diff --git a/src/test/kotlin/org/move/ide/annotator/errors/TypeParametersNumberErrorTest.kt b/src/test/kotlin/org/move/ide/annotator/errors/TypeParametersNumberErrorTest.kt index 9f7976872..b59d4473a 100644 --- a/src/test/kotlin/org/move/ide/annotator/errors/TypeParametersNumberErrorTest.kt +++ b/src/test/kotlin/org/move/ide/annotator/errors/TypeParametersNumberErrorTest.kt @@ -1,9 +1,9 @@ package org.move.ide.annotator.errors -import org.move.ide.annotator.ErrorAnnotator +import org.move.ide.annotator.MvErrorAnnotator import org.move.utils.tests.annotation.AnnotatorTestCase -class TypeParametersNumberErrorTest: AnnotatorTestCase(ErrorAnnotator::class) { +class TypeParametersNumberErrorTest: AnnotatorTestCase(MvErrorAnnotator::class) { fun `test missing type argument for vector`() = checkErrors(""" module 0x1::M { fun m() { diff --git a/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt b/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt index 310bf7479..59b9b1647 100644 --- a/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt @@ -2,8 +2,9 @@ package org.move.ide.inspections import org.move.utils.tests.annotation.InspectionTestBase -class MvTypeCheckInspectionTest: InspectionTestBase(MvTypeCheckInspection::class) { - fun `test incorrect type address passed where &signer is expected`() = checkErrors(""" +class MvTypeCheckInspectionTest : InspectionTestBase(MvTypeCheckInspection::class) { + fun `test incorrect type address passed where &signer is expected`() = checkErrors( + """ module 0x1::M { fun send(account: &signer) {} @@ -11,9 +12,11 @@ class MvTypeCheckInspectionTest: InspectionTestBase(MvTypeCheckInspection::class send(addr); } } - """) + """ + ) - fun `test incorrect type u8 passed where &signer is expected`() = checkErrors(""" + fun `test incorrect type u8 passed where &signer is expected`() = checkErrors( + """ module 0x1::M { fun send(account: &signer) {} @@ -21,9 +24,11 @@ class MvTypeCheckInspectionTest: InspectionTestBase(MvTypeCheckInspection::class send(addr) } } - """) + """ + ) - fun `test no errors if same type`() = checkErrors(""" + fun `test no errors if same type`() = checkErrors( + """ module 0x1::M { fun send(account: &signer) {} @@ -31,9 +36,11 @@ class MvTypeCheckInspectionTest: InspectionTestBase(MvTypeCheckInspection::class send(acc) } } - """) + """ + ) - fun `test mutable reference compatible with immutable reference`() = checkErrors(""" + fun `test mutable reference compatible with immutable reference`() = checkErrors( + """ module 0x1::M { struct Option { vec: vector @@ -78,7 +85,8 @@ class MvTypeCheckInspectionTest: InspectionTestBase(MvTypeCheckInspection::class """ ) - fun `test immutable reference is not compatible with mutable reference`() = checkErrors(""" + fun `test immutable reference is not compatible with mutable reference`() = checkErrors( + """ module 0x1::M { struct Option { vec: vector @@ -90,9 +98,11 @@ class MvTypeCheckInspectionTest: InspectionTestBase(MvTypeCheckInspection::class is_none(opt); } } - """) + """ + ) - fun `test incorrect type of argument with struct literal`() = checkErrors(""" + fun `test incorrect type of argument with struct literal`() = checkErrors( + """ module 0x1::M { struct A {} struct B {} @@ -102,9 +112,11 @@ class MvTypeCheckInspectionTest: InspectionTestBase(MvTypeCheckInspection::class use_a(B {}) } } - """) + """ + ) - fun `test incorrect type of argument with call expression`() = checkErrors(""" + fun `test incorrect type of argument with call expression`() = checkErrors( + """ module 0x1::M { struct A {} struct B {} @@ -116,9 +128,11 @@ class MvTypeCheckInspectionTest: InspectionTestBase(MvTypeCheckInspection::class use_a(get_b()) } } - """) + """ + ) - fun `test incorrect type of argument with call expression from different module`() = checkErrors(""" + fun `test incorrect type of argument with call expression from different module`() = checkErrors( + """ module 0x1::Other { struct B {} public fun get_b(): B { B {} } @@ -133,9 +147,11 @@ module 0x1::M { use_a(get_b()) } } - """) + """ + ) - fun `test bytearray is vector of u8`() = checkErrors(""" + fun `test bytearray is vector of u8`() = checkErrors( + """ module 0x1::M { fun send(a: vector) {} fun main() { @@ -143,9 +159,11 @@ module 0x1::M { send(a) } } - """) + """ + ) - fun `test no error for compatible generic with explicit parameter`() = checkErrors(""" + fun `test no error for compatible generic with explicit parameter`() = checkErrors( + """ module 0x1::M { struct Diem has store { val: u64 } struct Balance has key { @@ -160,9 +178,11 @@ module 0x1::M { value(coin) } } - """) + """ + ) - fun `test no error for compatible generic with inferred parameter`() = checkErrors(""" + fun `test no error for compatible generic with inferred parameter`() = checkErrors( + """ module 0x1::M { struct Diem has store { val: u64 } struct Balance has key { @@ -177,39 +197,48 @@ module 0x1::M { value(coin) } } - """) + """ + ) - fun `test no return type but returns u8`() = checkErrors(""" + fun `test no return type but returns u8`() = checkErrors( + """ module 0x1::M { fun call() { return 1; } } - """) + """ + ) - fun `test no return type but returns u8 with expression`() = checkErrors(""" + fun `test no return type but returns u8 with expression`() = checkErrors( + """ module 0x1::M { fun call() { 1 } } - """) + """ + ) - fun `test if statement returns ()`() = checkErrors(""" + fun `test if statement returns ()`() = checkErrors( + """ module 0x1::M { fun m() { if (true) {1} else {2}; } } - """) + """ + ) - fun `test block expr returns ()`() = checkErrors(""" + fun `test block expr returns ()`() = checkErrors( + """ module 0x1::M { fun m() { {1}; } } - """) + """ + ) fun `test error on code block if empty block and return type`() = checkErrors( """ @@ -231,21 +260,25 @@ module 0x1::M { """ ) - fun `test if condition should be boolean`() = checkErrors(""" + fun `test if condition should be boolean`() = checkErrors( + """ module 0x1::M { fun m() { if (1) 1; } } - """) + """ + ) - fun `test incompatible types from branches`() = checkErrors(""" + fun `test incompatible types from branches`() = checkErrors( + """ module 0x1::M { fun m() { if (true) {1} else {true}; } } - """) + """ + ) fun `test no type error with explicit generic as move_to`() = checkErrors( """ @@ -269,7 +302,8 @@ module 0x1::M { """ ) - fun `test type check incompatible constraints`() = checkErrors(""" + fun `test type check incompatible constraints`() = checkErrors( + """ module 0x1::M { struct C {} struct D {} @@ -278,7 +312,8 @@ module 0x1::M { new(C {}, D {}); } } - """) + """ + ) fun `test error if resolved type requires a reference`() = checkErrors( """ @@ -294,7 +329,8 @@ module 0x1::M { """ ) - fun `test return generic tuple from nested callable`() = checkErrors(""" + fun `test return generic tuple from nested callable`() = checkErrors( + """ module 0x1::M { struct MintCapability has key, store {} struct BurnCapability has key, store {} @@ -306,7 +342,8 @@ module 0x1::M { return (MintCapability{}, BurnCapability{}) } } - """) + """ + ) fun `test emit event requires mutable reference error`() = checkErrors( """ @@ -328,7 +365,8 @@ module 0x1::M { """ ) - fun `test fields of struct should have abilities of struct`() = checkErrors(""" + fun `test fields of struct should have abilities of struct`() = checkErrors( + """ module 0x1::M { struct A {} @@ -336,9 +374,11 @@ module 0x1::M { a: A } } - """) + """ + ) - fun `test key struct requires store fields`() = checkErrors(""" + fun `test key struct requires store fields`() = checkErrors( + """ module 0x1::M { struct A {} @@ -346,9 +386,11 @@ module 0x1::M { a: A } } - """) + """ + ) - fun `test store struct requires store fields`() = checkErrors(""" + fun `test store struct requires store fields`() = checkErrors( + """ module 0x1::M { struct A {} @@ -356,9 +398,11 @@ module 0x1::M { a: A } } - """) + """ + ) - fun `test copy struct requires copy fields`() = checkErrors(""" + fun `test copy struct requires copy fields`() = checkErrors( + """ module 0x1::M { struct A {} @@ -366,9 +410,11 @@ module 0x1::M { a: A } } - """) + """ + ) - fun `test drop struct requires drop fields`() = checkErrors(""" + fun `test drop struct requires drop fields`() = checkErrors( + """ module 0x1::M { struct A {} @@ -376,9 +422,11 @@ module 0x1::M { a: A } } - """) + """ + ) - fun `test function invocation with explicitly provided generic type`() = checkErrors(""" + fun `test function invocation with explicitly provided generic type`() = checkErrors( + """ module 0x1::Event { struct Message has drop {} @@ -388,9 +436,11 @@ module 0x1::M { emit_event<Message>() } } - """) + """ + ) - fun `test struct constructor with explicitly provided generic type`() = checkErrors(""" + fun `test struct constructor with explicitly provided generic type`() = checkErrors( + """ module 0x1::Event { struct Message has drop {} @@ -400,9 +450,11 @@ module 0x1::M { Event<Message> {}; } } - """) + """ + ) - fun `test type param`() = checkErrors(""" + fun `test type param`() = checkErrors( + """ module 0x1::Event { struct Message has drop {} @@ -412,28 +464,34 @@ module 0x1::M { emit_event<M>() } } - """) + """ + ) - fun `test no required ability 'key' for move_to argument`() = checkErrors(""" + fun `test no required ability 'key' for move_to argument`() = checkErrors( + """ module 0x1::M { struct Res {} fun main(s: &signer, r: Res) { move_to(s, r) } } - """) + """ + ) - fun `test no error in move_to with resource`() = checkErrors(""" + fun `test no error in move_to with resource`() = checkErrors( + """ module 0x1::M { struct Res has key {} fun main(s: &signer, r: Res) { move_to(s, r) } } - """) + """ + ) - fun `test no required ability for struct for type param`() = checkErrors(""" + fun `test no required ability for struct for type param`() = checkErrors( + """ module 0x1::M { struct Res {} fun save(r: T) {} @@ -441,9 +499,11 @@ module 0x1::M { save(r) } } - """) + """ + ) - fun `test no error in type param if structure has required abilities`() = checkErrors(""" + fun `test no error in type param if structure has required abilities`() = checkErrors( + """ module 0x1::M { struct Res has key {} fun save(r: T) {} @@ -451,45 +511,55 @@ module 0x1::M { save(r) } } - """) + """ + ) - fun `test no error in specs`() = checkErrors(""" + fun `test no error in specs`() = checkErrors( + """ module 0x1::M { fun balance() {} spec schema PayFromEnsures { ensures balance(); } } - """) + """ + ) - fun `test pass primitive type to generic with required abilities`() = checkErrors(""" + fun `test pass primitive type to generic with required abilities`() = checkErrors( + """ module 0x1::M { fun balance(k: Token) {} fun m() { balance(@0x1); } } - """) + """ + ) - fun `test pass generic with abilities when primitive type is expected`() = checkErrors(""" + fun `test pass generic with abilities when primitive type is expected`() = checkErrors( + """ module 0x1::M { fun count(val: u8) {} fun balance(k: Token) { count(k); } } - """) + """ + ) - fun `test invalid type for field in struct literal`() = checkErrors(""" + fun `test invalid type for field in struct literal`() = checkErrors( + """ module 0x1::M { struct Deal { val: u8 } fun main() { Deal { val: false }; } } - """) + """ + ) - fun `test valid type for field`() = checkErrors(""" + fun `test valid type for field`() = checkErrors( + """ module 0x1::M { struct Deal { val: u8 } fun main() { @@ -497,9 +567,11 @@ module 0x1::M { Deal { val: 10u8 }; } } - """) + """ + ) - fun `test no need for explicit type parameter if inferrable from context`() = checkErrors(""" + fun `test no need for explicit type parameter if inferrable from context`() = checkErrors( + """ module 0x1::M { struct Option has copy, drop, store {} public fun none(): Option { @@ -511,9 +583,11 @@ module 0x1::M { } } - """) + """ + ) - fun `test no need for vector empty() generic`() = checkErrors(""" + fun `test no need for vector empty() generic`() = checkErrors( + """ module 0x1::M { /// Create an empty vector. native public fun empty(): vector; @@ -524,9 +598,11 @@ module 0x1::M { CapState { delegates: empty() }; } } - """) + """ + ) - fun `test type error in struct literal field shorthand`() = checkErrors(""" + fun `test type error in struct literal field shorthand`() = checkErrors( + """ module 0x1::M { struct S { a: u8 } fun m() { @@ -534,9 +610,11 @@ module 0x1::M { S { a }; } } - """) + """ + ) - fun `test do not crash type checking invalid number of type params or call params`() = checkErrors(""" + fun `test do not crash type checking invalid number of type params or call params`() = checkErrors( + """ module 0x1::M { struct S { val: R } fun call(a: u8) {} @@ -545,24 +623,30 @@ module 0x1::M { call(1, 2, 3); } } - """) + """ + ) - fun `test explicit unit return`() = checkErrors(""" + fun `test explicit unit return`() = checkErrors( + """ module 0x1::M { fun m(): () {} } - """) + """ + ) - fun `test if else with references no error if coerceable`() = checkErrors(""" + fun `test if else with references no error if coerceable`() = checkErrors( + """ module 0x1::M { struct S {} fun m(s: &S, s_mut: &mut S) { (if (cond) s_mut else s); } } - """) + """ + ) - fun `test incorrect type address passed where &signer is expected in spec`() = checkErrors(""" + fun `test incorrect type address passed where &signer is expected in spec`() = checkErrors( + """ module 0x1::M { fun send(account: &signer) {} @@ -570,9 +654,11 @@ module 0x1::M { send(@0x1) } } - """) + """ + ) - fun `test signer compatibility in spec`() = checkErrors(""" + fun `test signer compatibility in spec`() = checkErrors( + """ module 0x1::M { fun address_of(account: &signer): address { @0x1 } fun send(account: &signer) {} @@ -580,9 +666,11 @@ module 0x1::M { address_of(account); } } - """) + """ + ) - fun `test vector_u8 is compatible with vector_num inside spec`() = checkErrors(""" + fun `test vector_u8 is compatible with vector_num inside spec`() = checkErrors( + """ module 0x1::M { struct S { val: vector @@ -591,9 +679,11 @@ module 0x1::M { S { val: b"" }; } } - """) + """ + ) - fun `test ref equality for generics in call expr`() = checkErrors(""" + fun `test ref equality for generics in call expr`() = checkErrors( + """ module 0x1::M { struct Token {} fun call(ref: &Token) { @@ -603,18 +693,22 @@ module 0x1::M { } } } - """) + """ + ) - fun `test invalid argument to plus expr`() = checkErrors(""" + fun `test invalid argument to plus expr`() = checkErrors( + """ module 0x1::M { fun add(a: bool, b: bool) { a + b; } } - """) + """ + ) - fun `test no error if return nested in if and while`() = checkErrors(""" + fun `test no error if return nested in if and while`() = checkErrors( + """ module 0x1::M { fun main(): u8 { let i = 0; @@ -624,18 +718,22 @@ module 0x1::M { i } } - """) + """ + ) - fun `test no error empty return`() = checkErrors(""" + fun `test no error empty return`() = checkErrors( + """ module 0x1::M { fun main() { if (true) return return } } - """) + """ + ) - fun `test no error return tuple from if else`() = checkErrors(""" + fun `test no error return tuple from if else`() = checkErrors( + """ module 0x1::M { fun main(): (u8, u8) { if (true) { @@ -645,9 +743,11 @@ module 0x1::M { } } } - """) + """ + ) - fun `test no error return tuple from nested if else`() = checkErrors(""" + fun `test no error return tuple from nested if else`() = checkErrors( + """ module 0x1::M { fun main(): (u8, u8) { if (true) { @@ -661,9 +761,11 @@ module 0x1::M { } } } - """) + """ + ) - fun `test error add to bool in assignment expr`() = checkErrors(""" + fun `test error add to bool in assignment expr`() = checkErrors( + """ module 0x1::M { fun main() { let a = 1u64; @@ -671,27 +773,33 @@ module 0x1::M { a = a + b; } } - """) + """ + ) - fun `test error invalid assignment type`() = checkErrors(""" + fun `test error invalid assignment type`() = checkErrors( + """ module 0x1::M { fun main() { let a = 1u64; a = false; } } - """) + """ + ) - fun `test tuple unpacking with three elements when two is specified`() = checkErrors(""" + fun `test tuple unpacking with three elements when two is specified`() = checkErrors( + """ module 0x1::M { fun tuple(): (u8, u8, u8) { (1, 1, 1) } fun main() { let (a, b) = tuple(); } } - """) + """ + ) - fun `test tuple unpacking no nested errors`() = checkErrors(""" + fun `test tuple unpacking no nested errors`() = checkErrors( + """ module 0x1::M { struct S { val: u8 } fun tuple(): (u8, u8, u8) { (1, 1, 1) } @@ -699,9 +807,11 @@ module 0x1::M { let (S { val }, b) = tuple(); } } - """) + """ + ) - fun `test tuple unpacking into struct when tuple pat is expected is specified`() = checkErrors(""" + fun `test tuple unpacking into struct when tuple pat is expected is specified`() = checkErrors( + """ module 0x1::M { struct S { val: u8 } fun tuple(): (u8, u8, u8) { (1, 1, 1) } @@ -709,9 +819,11 @@ module 0x1::M { let S { val } = tuple(); } } - """) + """ + ) - fun `test unpacking struct into field`() = checkErrors(""" + fun `test unpacking struct into field`() = checkErrors( + """ module 0x1::M { struct S { val: u8 } fun s(): S { S { val: 10 } } @@ -719,9 +831,11 @@ module 0x1::M { let s = s(); } } - """) + """ + ) - fun `test error unpacking struct into tuple`() = checkErrors(""" + fun `test error unpacking struct into tuple`() = checkErrors( + """ module 0x1::M { struct S { val: u8 } fun s(): S { S { val: 10 } } @@ -729,18 +843,22 @@ module 0x1::M { let (a, b) = s(); } } - """) + """ + ) - fun `test error parameter type with return type inferred`() = checkErrors(""" + fun `test error parameter type with return type inferred`() = checkErrors( + """ module 0x1::M { fun identity(a: T): T { a } fun main() { let a: u8 = identity(1u64); } } - """) + """ + ) - fun `test no error integer should ignore spec blocks`() = checkErrors(""" + fun `test no error integer should ignore spec blocks`() = checkErrors( + """ module 0x1::main { spec fun spec_pow(y: u64, x: u64): u64 { if (x == 0) { @@ -767,5 +885,42 @@ module 0x1::M { res } } + """ + ) + + fun `test missing key ability with quickfix`() = checkFixByText( + "Add 'key' ability to Cat", + """ + module 0x1::main { + struct Cat has drop {} + struct S {} + fun main() { + S</*caret*/Cat> {}; + } + } + """, """ + module 0x1::main { + struct Cat has drop, key {} + struct S {} + fun main() { + S {}; + } + } + """ + ) + + fun `test no missing ability quickfix in other module struct`() = checkFixIsUnavailable( + "Add 'key' ability to Cat", + """ + module 0x1::pets { + struct Cat {} + } + module 0x1::main { + use 0x1::pets::Cat; + struct S {} + fun main() { + S</*caret*/Cat> {}; + } + } """) } diff --git a/src/test/kotlin/org/move/ide/inspections/MvUnusedVariableInspectionTest.kt b/src/test/kotlin/org/move/ide/inspections/MvUnusedVariableInspectionTest.kt index 59e786b74..fc2b51d50 100644 --- a/src/test/kotlin/org/move/ide/inspections/MvUnusedVariableInspectionTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/MvUnusedVariableInspectionTest.kt @@ -2,25 +2,30 @@ package org.move.ide.inspections import org.move.utils.tests.annotation.InspectionTestBase -class MvUnusedVariableInspectionTest: InspectionTestBase(MvUnusedVariableInspection::class) { - fun `test used function parameter`() = checkByText(""" +class MvUnusedVariableInspectionTest : InspectionTestBase(MvUnusedVariableInspection::class) { + fun `test used function parameter`() = checkByText( + """ module 0x1::M { fun call(a: u8): u8 { a + 1 } } - """) + """ + ) - fun `test used variable`() = checkByText(""" + fun `test used variable`() = checkByText( + """ module 0x1::M { fun call(): u8 { let a = 1; a + 1 } } - """) + """ + ) - fun `test unused function parameter`() = checkFixByText("Rename to _a", """ + fun `test unused function parameter rename fix`() = checkFixByText( + "Rename to _a", """ module 0x1::M { fun call(/*caret*/a: u8): u8 { 1 @@ -32,9 +37,11 @@ class MvUnusedVariableInspectionTest: InspectionTestBase(MvUnusedVariableInspect 1 } } - """) + """ + ) - fun `test unused variable`() = checkFixByText("Rename to _a", """ + fun `test unused variable`() = checkFixByText( + "Rename to _a", """ module 0x1::M { fun call(): u8 { let /*caret*/a = 1; @@ -46,17 +53,21 @@ class MvUnusedVariableInspectionTest: InspectionTestBase(MvUnusedVariableInspect let _a = 1; } } - """) + """ + ) - fun `test no error if prefixed with underscore`() = checkByText(""" + fun `test no error if prefixed with underscore`() = checkByText( + """ module 0x1::M { fun call(_a: u8) { let _b = 1; } } - """) + """ + ) - fun `test unused signer in unit test`() = checkFixByText("Rename to _validator_acc", """ + fun `test unused signer in unit test`() = checkFixByText( + "Rename to _validator_acc", """ module 0x1::M { #[test(validator_acc = @0x42)] fun test_function(/*caret*/validator_acc: signer) { @@ -70,5 +81,6 @@ class MvUnusedVariableInspectionTest: InspectionTestBase(MvUnusedVariableInspect } } - """) + """ + ) } diff --git a/src/test/kotlin/org/move/ide/inspections/RedundantQualifiedPathInspectionTest.kt b/src/test/kotlin/org/move/ide/inspections/RedundantQualifiedPathInspectionTest.kt index faeb50c6b..5631936dc 100644 --- a/src/test/kotlin/org/move/ide/inspections/RedundantQualifiedPathInspectionTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/RedundantQualifiedPathInspectionTest.kt @@ -182,4 +182,31 @@ class RedundantQualifiedPathInspectionTest : InspectionTestBase(RedundantQualifi } } """) + + fun `test remove redundant qualifier with specified generic`() = checkFixByText( + "Remove redundant qualifier", """ + module 0x1::M { + public fun call() {} + } + module 0x1::M2 { + use 0x1::M; + use 0x1::M::call; + fun m() { + 0x1::M/*caret*/::call(); + } + } + """, """ + module 0x1::M { + public fun call() {} + } + module 0x1::M2 { + use 0x1::M; + use 0x1::M::call; + fun m() { + /*caret*/call(); + } + } + """ + ) + } diff --git a/src/test/kotlin/org/move/ide/inspections/fixes/RemoveParameterFixTest.kt b/src/test/kotlin/org/move/ide/inspections/fixes/RemoveParameterFixTest.kt new file mode 100644 index 000000000..36f4bc5c0 --- /dev/null +++ b/src/test/kotlin/org/move/ide/inspections/fixes/RemoveParameterFixTest.kt @@ -0,0 +1,140 @@ +package org.move.ide.inspections.fixes + +import org.move.ide.inspections.MvUnusedVariableInspection +import org.move.utils.tests.annotation.InspectionTestBase + +class RemoveParameterFixTest: InspectionTestBase(MvUnusedVariableInspection::class) { + fun `test single parameter`() = checkFixByText( + "Remove parameter", """ + module 0x1::M { + fun call(/*caret*/a: u8): u8 { + 1 + } + fun main() { + call(1); + } + } + """, """ + module 0x1::M { + fun call(): u8 { + 1 + } + fun main() { + call(); + } + } + """ + ) + + fun `test first of two`() = checkFixByText( + "Remove parameter", """ + module 0x1::M { + fun call(/*caret*/a: u8, b: u8): u8 { + b + } + fun main() { + call(1, 2); + } + } + """, """ + module 0x1::M { + fun call(b: u8): u8 { + b + } + fun main() { + call(2); + } + } + """ + ) + + fun `test first of two multiline`() = checkFixByText( + "Remove parameter", """ + module 0x1::M { + fun call( + /*caret*/a: u8, + b: u8 + ): u8 { + b + } + fun main() { + call( + 1, + 2 + ); + } + } + """, """ + module 0x1::M { + fun call( + b: u8 + ): u8 { + b + } + fun main() { + call( + 2 + ); + } + } + """ + ) + + fun `test second of three`() = checkFixByText( + "Remove parameter", """ + module 0x1::M { + fun call(x: u8, /*caret*/a: u8, b: u8): u8 { + x + b + } + fun main() { + call(0, 1, 2); + } + } + """, """ + module 0x1::M { + fun call(x: u8, b: u8): u8 { + x + b + } + fun main() { + call(0, 2); + } + } + """ + ) + + fun `test second of three multiline`() = checkFixByText( + "Remove parameter", """ + module 0x1::M { + fun call( + x: u8, + /*caret*/a: u8, + b: u8 + ): u8 { + x + b + } + fun main() { + call( + 0, + 1, + 2 + ); + } + } + """, """ + module 0x1::M { + fun call( + x: u8, + b: u8 + ): u8 { + x + b + } + fun main() { + call( + 0, + 2 + ); + } + } + """ + ) +} diff --git a/src/test/kotlin/org/move/ide/intentions/ChopValueArgumentListIntentionTest.kt b/src/test/kotlin/org/move/ide/intentions/ChopValueArgumentListIntentionTest.kt new file mode 100644 index 000000000..188ea26dc --- /dev/null +++ b/src/test/kotlin/org/move/ide/intentions/ChopValueArgumentListIntentionTest.kt @@ -0,0 +1,25 @@ +package org.move.ide.intentions + +import org.move.utils.tests.MvIntentionTestCase + +class ChopValueArgumentListIntentionTest: MvIntentionTestCase(ChopValueArgumentListIntention::class) { + fun `test separate arguments in call expr`() = doAvailableTest(""" +module 0x1::main { + fun call(foo: u8, bar: u8, baz: u8) {} + fun main() { + call(/*caret*/1, 2, 3); + } +} + """, """ +module 0x1::main { + fun call(foo: u8, bar: u8, baz: u8) {} + fun main() { + call( + 1, + 2, + 3 + ); + } +} + """) +} diff --git a/src/test/resources/org/move/lang/parser/complete/expressions.move b/src/test/resources/org/move/lang/parser/complete/expressions.move index 55e175beb..d4bbddf25 100644 --- a/src/test/resources/org/move/lang/parser/complete/expressions.move +++ b/src/test/resources/org/move/lang/parser/complete/expressions.move @@ -5,6 +5,8 @@ module M { 1 % 2; 1 ^ 2; + (a * b as u64); + *a = 1 + 2 * (3 + 5) * 4; a < b && b > 2; diff --git a/src/test/resources/org/move/lang/parser/complete/expressions.txt b/src/test/resources/org/move/lang/parser/complete/expressions.txt index 3794aa700..17892c913 100644 --- a/src/test/resources/org/move/lang/parser/complete/expressions.txt +++ b/src/test/resources/org/move/lang/parser/complete/expressions.txt @@ -101,6 +101,29 @@ FILE PsiElement(INTEGER_LITERAL)('2') PsiElement(;)(';') PsiWhiteSpace('\n\n ') + MvExprStmtImpl(EXPR_STMT) + MvParensExprImpl(PARENS_EXPR) + PsiElement(()('(') + MvCastExprImpl(CAST_EXPR) + MvMulExprImpl(MUL_EXPR) + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('a') + PsiWhiteSpace(' ') + PsiElement(*)('*') + PsiWhiteSpace(' ') + MvRefExprImpl(REF_EXPR) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('b') + PsiWhiteSpace(' ') + PsiElement(as)('as') + PsiWhiteSpace(' ') + MvPathTypeImpl(PATH_TYPE) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('u64') + PsiElement())(')') + PsiElement(;)(';') + PsiWhiteSpace('\n\n ') MvExprStmtImpl(EXPR_STMT) MvAssignmentExprImpl(ASSIGNMENT_EXPR) MvDerefExprImpl(DEREF_EXPR) From 0f9e1a4ad8e9ec78fd29ccc48607e7c27161f0c2 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Fri, 16 Sep 2022 18:55:23 +0200 Subject: [PATCH 08/26] refactor binary operatos --- changelog/1.20.0.md | 8 +- src/main/grammars/MoveParser.bnf | 139 +++++++---- .../org/move/ide/formatter/impl/spacing.kt | 5 +- .../org/move/ide/formatter/impl/utils.kt | 10 +- .../inspections/MvUnusedVariableInspection.kt | 3 + .../org/move/lang/core/MoveTokenType.kt | 12 + .../move/lang/core/psi/ext/MvBinaryExpr.kt | 15 ++ .../org/move/lang/core/psi/ext/MvBinaryOp.kt | 10 + .../MvFunctionParameter.kt} | 3 + .../move/lang/core/types/infer/Expressions.kt | 35 ++- .../description.html | 0 .../inspections/MvTypeCheckInspectionTest.kt | 9 + .../MvUnusedVariableInspectionTest.kt | 6 + .../fixes/RemoveParameterFixTest.kt | 32 +++ .../move/lang/resolve/ResolveFunctionTest.kt | 14 ++ .../lang/types/ExpressionTypeInferenceTest.kt | 11 + .../complete/contextual_token_operators.txt | 40 +-- .../move/lang/parser/complete/expressions.txt | 80 +++--- .../complete/expressions_angle_brackets.txt | 50 ++-- .../complete/expressions_assignments.txt | 20 +- .../parser/complete/expressions_specs.txt | 40 +-- .../move/lang/parser/complete/generics.txt | 10 +- .../lang/parser/complete/struct_literals.txt | 10 +- .../complete/while_loop_inline_assignment.txt | 45 ++-- .../move/lang/parser/partial/assignments.txt | 23 +- .../lang/parser/partial/function_calls.txt | 10 +- .../move/lang/parser/partial/module_const.txt | 2 +- .../org/move/lang/parser/partial/spec.txt | 9 +- .../org/move/lang/parser/specs/conditions.txt | 235 +++++++++++------- .../move/lang/parser/specs/forall_exists.txt | 60 +++-- .../lang/parser/specs/spec_statements.txt | 49 ++-- 31 files changed, 652 insertions(+), 343 deletions(-) create mode 100644 src/main/kotlin/org/move/lang/core/psi/ext/MvBinaryExpr.kt create mode 100644 src/main/kotlin/org/move/lang/core/psi/ext/MvBinaryOp.kt rename src/main/kotlin/org/move/lang/core/psi/{mixins/MoveFunctionParameterMixin.kt => ext/MvFunctionParameter.kt} (73%) rename src/main/resources/intentionDescriptions/{ChopArgumentListIntention => ChopValueArgumentListIntention}/description.html (100%) diff --git a/changelog/1.20.0.md b/changelog/1.20.0.md index ab31778c1..b8727d407 100644 --- a/changelog/1.20.0.md +++ b/changelog/1.20.0.md @@ -14,7 +14,9 @@ TODO: screenshot * Sort completion in borrow exprs. -* Sort completions by abilities in type parameters. +* Sort completions by abilities in type parameters. + +* Support imports inside code blocks. ## Fixes @@ -22,4 +24,8 @@ TODO: screenshot * Fix caching issue that lead to undeterministic type checking in some cases. +* Fix "unused parameter" error on native functions. + +* Fix struct unpacking type inference. + ## Internal diff --git a/src/main/grammars/MoveParser.bnf b/src/main/grammars/MoveParser.bnf index 07356c06d..a1430387d 100644 --- a/src/main/grammars/MoveParser.bnf +++ b/src/main/grammars/MoveParser.bnf @@ -21,11 +21,15 @@ extends("(Lambda|Ref|Path|Tuple|Unit)Type")=Type // extends(".*SpecDef")=AnySpec - extends(".*Stmt")=Stmt + elementType(".+BinExpr")=BinaryExpr + elementType(".+BinOp")=BinaryOp + name(".+BinOp")="operator" name(".*Expr")="expression" -// consumeTokenMethod(".*Expr") = "consumeTokenFast" + extends(".*Stmt")=Stmt + + consumeTokenMethod("((?!.*_with_recover).*_recover)|(.*_first)|(.*Expr)") = "consumeTokenFast" tokens = [ WHITESPACE='regexp:[ \n\t\r\f]' @@ -738,26 +742,42 @@ Expr ::= AssignmentExpr | RangeExpr | (ForallQuantExpr | ExistsQuantExpr | ChooseQuantExpr) | CastExpr - | ImplyOperatorsExpr_items - | OrExpr - | AndExpr - | LogicalEqExprItem - | BitOrExpr - | BitXorExpr - | BitAndExpr - | (LeftShiftExpr | RightShiftExpr) - | AddExprItem - | MulExprItem - | ControlFlowExpr + | ImplyBinExpr_items + | OrBinExpr + | AndBinExpr + | LogicalEqExpr_items + | BitOrBinExpr + | BitXorBinExpr + | BitAndBinExpr + | (LeftShiftBinExpr | RightShiftBinExpr) + | AddExpr_items + | MulExpr_items + | ControlFlowExpr_items | UnaryExpr | BorrowExpr | AtomExpr -private MulExprItem ::= DivExpr | MulExpr | ModExpr -private AddExprItem ::= PlusExpr | MinusExpr -private LogicalEqExprItem ::= EqualsExpr | NotEqualsExpr | LessEqualsExpr | LessExpr | GreaterEqualsExpr | GreaterExpr +fake BinaryExpr ::= Expr BinaryOp Expr { + methods = [ + left="/Expr[0]" + right="/Expr[1]" + ] + mixin = "org.move.lang.core.psi.ext.MvBinaryExprMixin" +} + +fake BinaryOp ::= '==>' | '=' + | '==' | '!=' + | '<' | '>' | '<=' | '>=' + | '<<' | '>>' + | '+' | '-' | '*' | '/' | '%' + | '||' | '&&' | '|' | '&' | '^' + -private ControlFlowExpr ::= IfExpr | LoopExpr | WhileExpr +private MulExpr_items ::= DivBinExpr | MulBinExpr | ModBinExpr +private AddExpr_items ::= PlusBinExpr | MinusBinExpr +private LogicalEqExpr_items ::= EqualsBinExpr | NotEqualsBinExpr | LessEqualsBinExpr | LessBinExpr | GreaterEqualsBinExpr | GreaterBinExpr + +private ControlFlowExpr_items ::= IfExpr | LoopExpr | WhileExpr private UnaryExpr ::= CopyExpr | MoveExpr | DerefExpr | BangExpr | ReturnExpr | ContinueExpr | BreakExpr | AbortExpr private AtomExpr ::= @@ -774,38 +794,71 @@ private AtomExpr ::= | LitExpr | CodeBlockExpr -EqualsExpr ::= Expr (!eqeq_gt '==') Expr -NotEqualsExpr ::= Expr '!=' Expr - -OrExpr ::= Expr oror Expr -AndExpr ::= Expr andand Expr - -LessExpr ::= Expr (!(ltlt | lt_eqeq_gt) '<') Expr -GreaterExpr ::= Expr (!gtgt '>') Expr -LessEqualsExpr ::= Expr lteq Expr -GreaterEqualsExpr ::= Expr gteq Expr - -BitOrExpr ::= Expr (!oror '|') Expr -BitAndExpr ::= Expr (!andand '&') Expr -BitXorExpr ::= Expr '^' Expr CastExpr ::= Expr as Type private AnnotatedExpPrefix ::= '(' Expr ':' AnnotatedExpr ::= AnnotatedExpPrefix Type ')' { pin = 1 } -MulExpr ::= Expr '*' Expr -DivExpr ::= Expr '/' Expr -PlusExpr ::= Expr '+' Expr -MinusExpr ::= Expr '-' Expr -ModExpr ::= Expr '%' Expr - -LeftShiftExpr ::= Expr ltlt Expr -RightShiftExpr ::= Expr gtgt Expr - -private ImplyOperatorsExpr_items ::= ImplyOperatorExpr | PartialImplyOperatorExpr -ImplyOperatorExpr ::= Expr <> Expr -PartialImplyOperatorExpr ::= Expr <> Expr +EqualsBinExpr ::= Expr (!eqeq_gt EqualsBinOp) Expr +NotEqualsBinExpr ::= Expr NotEqualsBinOp Expr + +EqualsBinOp ::= '==' +NotEqualsBinOp ::= '!=' + +// booleans +OrBinExpr ::= Expr OrBinOp Expr +AndBinExpr ::= Expr AndBinOp Expr + +OrBinOp ::= oror +AndBinOp ::= andand + +LessBinExpr ::= Expr (!(ltlt | lt_eqeq_gt) LessBinOp) Expr +GreaterBinExpr ::= Expr (!gtgt GreaterBinOp) Expr +LessEqualsBinExpr ::= Expr LessEqualsBinOp Expr +GreaterEqualsBinExpr ::= Expr GreaterEqualsBinOp Expr + +LessBinOp ::= '<' +GreaterBinOp ::= '>' +LessEqualsBinOp ::= lteq +GreaterEqualsBinOp ::= gteq + +// bitwise ops +BitOrBinExpr ::= Expr (!oror BitOrBinOp) Expr +BitAndBinExpr ::= Expr (!andand BitAndBinOp) Expr +BitXorBinExpr ::= Expr BitXorBinOp Expr + +BitOrBinOp ::= '|' +BitAndBinOp ::= '&' +BitXorBinOp ::= '^' + +// arithmetic +MulBinExpr ::= Expr MulBinOp Expr +DivBinExpr ::= Expr DivBinOp Expr +PlusBinExpr ::= Expr PlusBinOp Expr +MinusBinExpr ::= Expr MinusBinOp Expr +ModBinExpr ::= Expr ModBinOp Expr + +MulBinOp ::= '*' +DivBinOp ::= '/' +PlusBinOp ::= '+' +MinusBinOp ::= '-' +ModBinOp ::= '%' + +// bit shifts +LeftShiftBinExpr ::= Expr LeftShiftBinOp Expr +RightShiftBinExpr ::= Expr RightShiftBinOp Expr + +LeftShiftBinOp ::= ltlt +RightShiftBinOp ::= gtgt + +// imply +private ImplyBinExpr_items ::= ImplyBinExpr | PartialImplyBinExpr +ImplyBinExpr ::= Expr ImplyBinOp Expr +PartialImplyBinExpr ::= Expr PartialImplyBinOp Expr + +ImplyBinOp ::= <> +PartialImplyBinOp ::= <> BangExpr ::= '!' Expr DerefExpr ::= '*' Expr diff --git a/src/main/kotlin/org/move/ide/formatter/impl/spacing.kt b/src/main/kotlin/org/move/ide/formatter/impl/spacing.kt index 3bdf36b71..92ca02d6c 100644 --- a/src/main/kotlin/org/move/ide/formatter/impl/spacing.kt +++ b/src/main/kotlin/org/move/ide/formatter/impl/spacing.kt @@ -14,6 +14,7 @@ import com.intellij.psi.tree.IElementType import com.intellij.psi.tree.TokenSet import org.move.ide.formatter.MvFmtContext import org.move.lang.MvElementTypes.* +import org.move.lang.core.MOVE_BINARY_OPS import org.move.lang.core.MOVE_COMMENTS import org.move.lang.core.MOVE_KEYWORDS import org.move.lang.core.psi.MvAddressBlock @@ -90,8 +91,10 @@ fun createSpacingBuilder(commonSettings: CommonCodeStyleSettings): SpacingBuilde ).spaces(0) .after(FUNCTION_VISIBILITY_MODIFIER).spaces(1) - .around(BINARY_OPS).spaces(1) + .around(BINARY_OP).spaces(1) + .around(EQ).spaces(1) .around(MOVE_KEYWORDS).spaces(1) + .applyForEach(BLOCK_LIKE) { before(it).spaces(1) } // .applyForEach(STRUCT_LITERAL_BLOCKS) { before(it).spaces(0) } } diff --git a/src/main/kotlin/org/move/ide/formatter/impl/utils.kt b/src/main/kotlin/org/move/ide/formatter/impl/utils.kt index bf9c6b56a..8f0232be0 100644 --- a/src/main/kotlin/org/move/ide/formatter/impl/utils.kt +++ b/src/main/kotlin/org/move/ide/formatter/impl/utils.kt @@ -10,11 +10,11 @@ import org.move.lang.core.psi.* import com.intellij.psi.tree.TokenSet.create as ts -val BINARY_OPS = ts( - PLUS, MINUS, MUL, DIV, MODULO, - OR, AND, OR_OR, AND_AND, - EQ, EQ_EQ, NOT_EQ, -) +//val BINARY_OPS = ts( +// PLUS, MINUS, MUL, DIV, MODULO, +// OR, AND, OR_OR, AND_AND, +// EQ, EQ_EQ, NOT_EQ, +//) val ONE_LINE_ITEMS = ts(USE_STMT, CONST) val PAREN_DELIMITED_BLOCKS = ts( diff --git a/src/main/kotlin/org/move/ide/inspections/MvUnusedVariableInspection.kt b/src/main/kotlin/org/move/ide/inspections/MvUnusedVariableInspection.kt index 307a64a86..3dae09484 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvUnusedVariableInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvUnusedVariableInspection.kt @@ -10,6 +10,7 @@ import org.move.ide.inspections.fixes.RemoveParameterFix import org.move.ide.inspections.fixes.RenameFix import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.owner +import org.move.lang.core.psi.mixins.functionLike class MvUnusedVariableInspection : MvLocalInspectionTool() { override fun buildMvVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) = @@ -22,6 +23,8 @@ class MvUnusedVariableInspection : MvLocalInspectionTool() { } override fun visitFunctionParameter(o: MvFunctionParameter) { + val functionLike = o.functionLike ?: return + if (functionLike.isNative) return val binding = o.bindingPat checkUnused(binding, "Unused function parameter") } diff --git a/src/main/kotlin/org/move/lang/core/MoveTokenType.kt b/src/main/kotlin/org/move/lang/core/MoveTokenType.kt index bfbb94466..727730551 100644 --- a/src/main/kotlin/org/move/lang/core/MoveTokenType.kt +++ b/src/main/kotlin/org/move/lang/core/MoveTokenType.kt @@ -25,3 +25,15 @@ val MOVE_KEYWORDS = tokenSetOf( val TYPES = tokenSetOf(PATH_TYPE, REF_TYPE, TUPLE_TYPE) val MOVE_COMMENTS = tokenSetOf(BLOCK_COMMENT, EOL_COMMENT, EOL_DOC_COMMENT) + +val MOVE_BINARY_OPS = tokenSetOf( + OR_OR, AND_AND, + EQ_EQ_GT, LT_EQ_EQ_GT, + LT, LT_EQ, GT, GT_EQ, + EQ, EQ_EQ, + OR, AND, XOR, + EQ, NOT_EQ, + MUL, DIV, MODULO, + PLUS, MINUS, + XOR, AND, OR +) diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvBinaryExpr.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvBinaryExpr.kt new file mode 100644 index 000000000..92f136310 --- /dev/null +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvBinaryExpr.kt @@ -0,0 +1,15 @@ +package org.move.lang.core.psi.ext + +import com.intellij.lang.ASTNode +import org.move.lang.MvElementTypes.BINARY_OP +import org.move.lang.core.MOVE_BINARY_OPS +import org.move.lang.core.psi.MvBinaryExpr +import org.move.lang.core.psi.MvElementImpl + +abstract class MvBinaryExprMixin(node: ASTNode): MvElementImpl(node), + MvBinaryExpr { + override fun toString(): String { + val op = node.findChildByType(BINARY_OP)?.text ?: "" + return "${javaClass.simpleName}(${node.elementType}[$op])" + } +} diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvBinaryOp.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvBinaryOp.kt new file mode 100644 index 000000000..57f0b751a --- /dev/null +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvBinaryOp.kt @@ -0,0 +1,10 @@ +package org.move.lang.core.psi.ext + +import com.intellij.psi.PsiElement +import org.move.lang.core.MOVE_BINARY_OPS +import org.move.lang.core.psi.MvBinaryOp + +val MvBinaryOp.operator: PsiElement + get() = requireNotNull(node.findChildByType(MOVE_BINARY_OPS)) { "guaranteed to be not-null by parser" }.psi + +val MvBinaryOp.op: String get() = operator.text diff --git a/src/main/kotlin/org/move/lang/core/psi/mixins/MoveFunctionParameterMixin.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvFunctionParameter.kt similarity index 73% rename from src/main/kotlin/org/move/lang/core/psi/mixins/MoveFunctionParameterMixin.kt rename to src/main/kotlin/org/move/lang/core/psi/ext/MvFunctionParameter.kt index 4de5dcfff..905acb602 100644 --- a/src/main/kotlin/org/move/lang/core/psi/mixins/MoveFunctionParameterMixin.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvFunctionParameter.kt @@ -1,5 +1,6 @@ package org.move.lang.core.psi.mixins +import org.move.lang.core.psi.MvFunctionLike import org.move.lang.core.psi.MvFunctionParameter import org.move.lang.core.types.infer.inferTypeTy import org.move.lang.core.types.ty.Ty @@ -7,3 +8,5 @@ import org.move.lang.core.types.ty.TyUnknown fun MvFunctionParameter.declaredTy(msl: Boolean): Ty = this.typeAnnotation?.type?.let { inferTypeTy(it, msl) } ?: TyUnknown + +val MvFunctionParameter.functionLike get() = this.parent.parent as? MvFunctionLike diff --git a/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt b/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt index fe0dbae65..543663f29 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt @@ -32,19 +32,8 @@ fun inferExprTy(expr: MvExpr, parentCtx: InferenceContext, expectedTy: Ty? = nul is MvCastExpr -> inferTypeTy(expr.type, parentCtx.msl) is MvParensExpr -> expr.expr?.let { inferExprTy(it, parentCtx) } ?: TyUnknown - is MvPlusExpr -> inferBinaryExprTy(expr.exprList, parentCtx) - is MvMinusExpr -> inferBinaryExprTy(expr.exprList, parentCtx) - is MvMulExpr -> inferBinaryExprTy(expr.exprList, parentCtx) - is MvDivExpr -> inferBinaryExprTy(expr.exprList, parentCtx) - is MvModExpr -> inferBinaryExprTy(expr.exprList, parentCtx) - + is MvBinaryExpr -> inferBinaryExprTy(expr, parentCtx) is MvBangExpr -> TyBool - is MvLessExpr -> TyBool - is MvLessEqualsExpr -> TyBool - is MvGreaterExpr -> TyBool - is MvGreaterEqualsExpr -> TyBool - is MvAndExpr -> TyBool - is MvOrExpr -> TyBool is MvIfExpr -> inferIfExprTy(expr, parentCtx, expectedTy) is MvWhileExpr -> inferWhileExprTy(expr, parentCtx) @@ -243,19 +232,27 @@ fun inferLitFieldInitExprTy(litField: MvStructLitField, ctx: InferenceContext): } } -private fun inferBinaryExprTy(exprList: List, ctx: InferenceContext): Ty { - val leftExpr = exprList.getOrNull(0) ?: return TyUnknown - val rightExpr = exprList.getOrNull(1) +private fun inferBinaryExprTy(binaryExpr: MvBinaryExpr, ctx: InferenceContext): Ty { + return when (binaryExpr.binaryOp.op) { + "<", ">", "<=", ">=", "==", "!=", "||", "&&", "==>", "<==>" -> inferBoolExprTy(binaryExpr, ctx) + "+", "-", "*", "/", "%" -> inferBinaryArithmeticExprTy(binaryExpr, ctx) + else -> TyUnknown + } +} + +private fun inferBinaryArithmeticExprTy(binaryExpr: MvBinaryExpr, ctx: InferenceContext): Ty { + val leftExpr = binaryExpr.left + val rightExpr = binaryExpr.right var typeErrorEncountered = false val leftExprTy = inferExprTy(leftExpr, ctx) - if (!leftExprTy.supportsBinaryOp()) { + if (!leftExprTy.supportsArithmeticOp()) { ctx.typeErrors.add(TypeError.UnsupportedBinaryOp(leftExpr, leftExprTy, "+")) typeErrorEncountered = true } if (rightExpr != null) { val rightExprTy = inferExprTy(rightExpr, ctx) - if (!rightExprTy.supportsBinaryOp()) { + if (!rightExprTy.supportsArithmeticOp()) { ctx.typeErrors.add(TypeError.UnsupportedBinaryOp(rightExpr, rightExprTy, "+")) typeErrorEncountered = true } @@ -266,7 +263,9 @@ private fun inferBinaryExprTy(exprList: List, ctx: InferenceContext): Ty return if (typeErrorEncountered) TyUnknown else leftExprTy } -private fun Ty.supportsBinaryOp(): Boolean { +private fun inferBoolExprTy(binaryExpr: MvBinaryExpr, ctx: InferenceContext): Ty { return TyBool } + +private fun Ty.supportsArithmeticOp(): Boolean { return this is TyInteger || this is TyNum || this is TyTypeParameter diff --git a/src/main/resources/intentionDescriptions/ChopArgumentListIntention/description.html b/src/main/resources/intentionDescriptions/ChopValueArgumentListIntention/description.html similarity index 100% rename from src/main/resources/intentionDescriptions/ChopArgumentListIntention/description.html rename to src/main/resources/intentionDescriptions/ChopValueArgumentListIntention/description.html diff --git a/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt b/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt index 59b9b1647..0eaa972bb 100644 --- a/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt @@ -923,4 +923,13 @@ module 0x1::M { } } """) + + fun `test no error unpacking a struct from move_from`() = checkByText(""" +module 0x1::main { + struct Container has key { val: u8 } + fun main() { + let Container { val } = move_from(source_addr); + } +} + """) } diff --git a/src/test/kotlin/org/move/ide/inspections/MvUnusedVariableInspectionTest.kt b/src/test/kotlin/org/move/ide/inspections/MvUnusedVariableInspectionTest.kt index fc2b51d50..e22d490fc 100644 --- a/src/test/kotlin/org/move/ide/inspections/MvUnusedVariableInspectionTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/MvUnusedVariableInspectionTest.kt @@ -83,4 +83,10 @@ class MvUnusedVariableInspectionTest : InspectionTestBase(MvUnusedVariableInspec } """ ) + + fun `test no unused parameter for native function`() = checkByText(""" +module 0x1::main { + native fun main(a: u8); +} + """) } diff --git a/src/test/kotlin/org/move/ide/inspections/fixes/RemoveParameterFixTest.kt b/src/test/kotlin/org/move/ide/inspections/fixes/RemoveParameterFixTest.kt index 36f4bc5c0..baab112b3 100644 --- a/src/test/kotlin/org/move/ide/inspections/fixes/RemoveParameterFixTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/fixes/RemoveParameterFixTest.kt @@ -80,6 +80,38 @@ class RemoveParameterFixTest: InspectionTestBase(MvUnusedVariableInspection::cla """ ) + fun `test second of two multiline`() = checkFixByText( + "Remove parameter", """ + module 0x1::M { + fun call( + b: u8, + /*caret*/a: u8, + ): u8 { + b + } + fun main() { + call( + 1, + 2 + ); + } + } + """, """ + module 0x1::M { + fun call( + b: u8 + ): u8 { + b + } + fun main() { + call( + 1 + ); + } + } + """ + ) + fun `test second of three`() = checkFixByText( "Remove parameter", """ module 0x1::M { diff --git a/src/test/kotlin/org/move/lang/resolve/ResolveFunctionTest.kt b/src/test/kotlin/org/move/lang/resolve/ResolveFunctionTest.kt index 18b52fb6d..4ba82e0b7 100644 --- a/src/test/kotlin/org/move/lang/resolve/ResolveFunctionTest.kt +++ b/src/test/kotlin/org/move/lang/resolve/ResolveFunctionTest.kt @@ -485,4 +485,18 @@ class ResolveFunctionTest : ResolveTestCase() { } } """) + + fun `test use item inside function block`() = checkByCode(""" +module 0x1::string { + public fun utf8() {} + //X +} +module 0x1::main { + fun main() { + use 0x1::string::utf8; + utf8(); + //^ + } +} + """) } diff --git a/src/test/kotlin/org/move/lang/types/ExpressionTypeInferenceTest.kt b/src/test/kotlin/org/move/lang/types/ExpressionTypeInferenceTest.kt index 8b106e943..6ad3902c3 100644 --- a/src/test/kotlin/org/move/lang/types/ExpressionTypeInferenceTest.kt +++ b/src/test/kotlin/org/move/lang/types/ExpressionTypeInferenceTest.kt @@ -265,4 +265,15 @@ class ExpressionTypeInferenceTest: TypificationTestCase() { } } """) + + fun `test struct unpacking type inference`() = testExpr(""" +module 0x1::main { + struct Container has key { val: u8 } + fun main() { + let container = move_from(source_addr); + let Container { val } = container; + //^ 0x1::main::Container + } +} + """) } diff --git a/src/test/resources/org/move/lang/parser/complete/contextual_token_operators.txt b/src/test/resources/org/move/lang/parser/complete/contextual_token_operators.txt index 00607b485..e4a410822 100644 --- a/src/test/resources/org/move/lang/parser/complete/contextual_token_operators.txt +++ b/src/test/resources/org/move/lang/parser/complete/contextual_token_operators.txt @@ -17,88 +17,96 @@ FILE PsiElement({)('{') PsiWhiteSpace('\n ') MvExprStmtImpl(EXPR_STMT) - MvLessExprImpl(LESS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[<]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(<)('<') + MvBinaryOpImpl(BINARY_OP) + PsiElement(<)('<') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('2') PsiElement(;)(';') PsiWhiteSpace('\n ') MvExprStmtImpl(EXPR_STMT) - MvGreaterExprImpl(GREATER_EXPR) + MvBinaryExprImpl(BINARY_EXPR[>]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(>)('>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>)('>') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('2') PsiElement(;)(';') PsiWhiteSpace('\n ') MvExprStmtImpl(EXPR_STMT) - MvLeftShiftExprImpl(LEFT_SHIFT_EXPR) + MvBinaryExprImpl(BINARY_EXPR[<<]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(<<)('<<') + MvBinaryOpImpl(BINARY_OP) + PsiElement(<<)('<<') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('2') PsiElement(;)(';') PsiWhiteSpace('\n ') MvExprStmtImpl(EXPR_STMT) - MvRightShiftExprImpl(RIGHT_SHIFT_EXPR) + MvBinaryExprImpl(BINARY_EXPR[>>]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(>>)('>>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>>)('>>') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('2') PsiElement(;)(';') PsiWhiteSpace('\n ') MvExprStmtImpl(EXPR_STMT) - MvAndExprImpl(AND_EXPR) + MvBinaryExprImpl(BINARY_EXPR[&&]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(&&)('&&') + MvBinaryOpImpl(BINARY_OP) + PsiElement(&&)('&&') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('2') PsiElement(;)(';') PsiWhiteSpace('\n ') MvExprStmtImpl(EXPR_STMT) - MvOrExprImpl(OR_EXPR) + MvBinaryExprImpl(BINARY_EXPR[||]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(||)('||') + MvBinaryOpImpl(BINARY_OP) + PsiElement(||)('||') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('2') PsiElement(;)(';') PsiWhiteSpace('\n ') MvExprStmtImpl(EXPR_STMT) - MvLessEqualsExprImpl(LESS_EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[<=]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(<=)('<=') + MvBinaryOpImpl(BINARY_OP) + PsiElement(<=)('<=') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('2') PsiElement(;)(';') PsiWhiteSpace('\n ') MvExprStmtImpl(EXPR_STMT) - MvGreaterEqualsExprImpl(GREATER_EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[>=]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(>=)('>=') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>=)('>=') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('2') diff --git a/src/test/resources/org/move/lang/parser/complete/expressions.txt b/src/test/resources/org/move/lang/parser/complete/expressions.txt index 17892c913..af75b5e2a 100644 --- a/src/test/resources/org/move/lang/parser/complete/expressions.txt +++ b/src/test/resources/org/move/lang/parser/complete/expressions.txt @@ -19,28 +19,31 @@ FILE PsiElement({)('{') PsiWhiteSpace('\n ') MvExprStmtImpl(EXPR_STMT) - MvMulExprImpl(MUL_EXPR) + MvBinaryExprImpl(BINARY_EXPR[*]) MvParensExprImpl(PARENS_EXPR) PsiElement(()('(') - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiElement())(')') PsiWhiteSpace(' ') - PsiElement(*)('*') + MvBinaryOpImpl(BINARY_OP) + PsiElement(*)('*') PsiWhiteSpace(' ') MvParensExprImpl(PARENS_EXPR) PsiElement(()('(') - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') @@ -48,10 +51,10 @@ FILE PsiElement(;)(';') PsiWhiteSpace('\n ') MvExprStmtImpl(EXPR_STMT) - MvMulExprImpl(MUL_EXPR) + MvBinaryExprImpl(BINARY_EXPR[*]) MvParensExprImpl(PARENS_EXPR) PsiElement(()('(') - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) MvBangExprImpl(BANG_EXPR) PsiElement(!)('!') MvBangExprImpl(BANG_EXPR) @@ -59,7 +62,8 @@ FILE MvLitExprImpl(LIT_EXPR) PsiElement(BOOL_LITERAL)('true') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiWhiteSpace(' ') MvBangExprImpl(BANG_EXPR) PsiElement(!)('!') @@ -69,7 +73,8 @@ FILE PsiElement(BOOL_LITERAL)('true') PsiElement())(')') PsiWhiteSpace(' ') - PsiElement(*)('*') + MvBinaryOpImpl(BINARY_OP) + PsiElement(*)('*') PsiWhiteSpace(' ') MvBangExprImpl(BANG_EXPR) PsiElement(!)('!') @@ -80,22 +85,24 @@ FILE PsiElement(;)(';') PsiWhiteSpace('\n ') MvExprStmtImpl(EXPR_STMT) - MvModExprImpl(MOD_EXPR) + MvBinaryExprImpl(BINARY_EXPR[%]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(%)('%') + MvBinaryOpImpl(BINARY_OP) + PsiElement(%)('%') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('2') PsiElement(;)(';') PsiWhiteSpace('\n ') MvExprStmtImpl(EXPR_STMT) - MvBitXorExprImpl(BIT_XOR_EXPR) + MvBinaryExprImpl(BINARY_EXPR[^]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(^)('^') + MvBinaryOpImpl(BINARY_OP) + PsiElement(^)('^') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('2') @@ -105,12 +112,13 @@ FILE MvParensExprImpl(PARENS_EXPR) PsiElement(()('(') MvCastExprImpl(CAST_EXPR) - MvMulExprImpl(MUL_EXPR) + MvBinaryExprImpl(BINARY_EXPR[*]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('a') PsiWhiteSpace(' ') - PsiElement(*)('*') + MvBinaryOpImpl(BINARY_OP) + PsiElement(*)('*') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -135,58 +143,65 @@ FILE MvInitializerImpl(INITIALIZER) PsiElement(=)('=') PsiWhiteSpace(' ') - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiWhiteSpace(' ') - MvMulExprImpl(MUL_EXPR) - MvMulExprImpl(MUL_EXPR) + MvBinaryExprImpl(BINARY_EXPR[*]) + MvBinaryExprImpl(BINARY_EXPR[*]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('2') PsiWhiteSpace(' ') - PsiElement(*)('*') + MvBinaryOpImpl(BINARY_OP) + PsiElement(*)('*') PsiWhiteSpace(' ') MvParensExprImpl(PARENS_EXPR) PsiElement(()('(') - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('3') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('5') PsiElement())(')') PsiWhiteSpace(' ') - PsiElement(*)('*') + MvBinaryOpImpl(BINARY_OP) + PsiElement(*)('*') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('4') PsiElement(;)(';') PsiWhiteSpace('\n\n ') MvExprStmtImpl(EXPR_STMT) - MvAndExprImpl(AND_EXPR) - MvLessExprImpl(LESS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[&&]) + MvBinaryExprImpl(BINARY_EXPR[<]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('a') PsiWhiteSpace(' ') - PsiElement(<)('<') + MvBinaryOpImpl(BINARY_OP) + PsiElement(<)('<') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('b') PsiWhiteSpace(' ') - PsiElement(&&)('&&') + MvBinaryOpImpl(BINARY_OP) + PsiElement(&&)('&&') PsiWhiteSpace(' ') - MvGreaterExprImpl(GREATER_EXPR) + MvBinaryExprImpl(BINARY_EXPR[>]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('b') PsiWhiteSpace(' ') - PsiElement(>)('>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>)('>') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('2') @@ -198,10 +213,11 @@ FILE MvPathImpl(PATH) PsiElement(IDENTIFIER)('v1') PsiElement([)('[') - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiElement(])(']') diff --git a/src/test/resources/org/move/lang/parser/complete/expressions_angle_brackets.txt b/src/test/resources/org/move/lang/parser/complete/expressions_angle_brackets.txt index 467c5e1ce..90615fbfb 100644 --- a/src/test/resources/org/move/lang/parser/complete/expressions_angle_brackets.txt +++ b/src/test/resources/org/move/lang/parser/complete/expressions_angle_brackets.txt @@ -17,83 +17,93 @@ FILE PsiElement({)('{') PsiWhiteSpace('\n ') MvExprStmtImpl(EXPR_STMT) - MvAndExprImpl(AND_EXPR) - MvLessExprImpl(LESS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[&&]) + MvBinaryExprImpl(BINARY_EXPR[<]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('a') PsiWhiteSpace(' ') - PsiElement(<)('<') + MvBinaryOpImpl(BINARY_OP) + PsiElement(<)('<') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('b') PsiWhiteSpace(' ') - PsiElement(&&)('&&') + MvBinaryOpImpl(BINARY_OP) + PsiElement(&&)('&&') PsiWhiteSpace(' ') - MvGreaterExprImpl(GREATER_EXPR) + MvBinaryExprImpl(BINARY_EXPR[>]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('b') PsiWhiteSpace(' ') - PsiElement(>)('>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>)('>') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('2') PsiElement(;)(';') PsiWhiteSpace('\n ') MvExprStmtImpl(EXPR_STMT) - MvAndExprImpl(AND_EXPR) - MvLessEqualsExprImpl(LESS_EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[&&]) + MvBinaryExprImpl(BINARY_EXPR[<=]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('a') PsiWhiteSpace(' ') - PsiElement(<=)('<=') + MvBinaryOpImpl(BINARY_OP) + PsiElement(<=)('<=') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('b') PsiWhiteSpace(' ') - PsiElement(&&)('&&') + MvBinaryOpImpl(BINARY_OP) + PsiElement(&&)('&&') PsiWhiteSpace(' ') - MvGreaterExprImpl(GREATER_EXPR) + MvBinaryExprImpl(BINARY_EXPR[>]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('b') PsiWhiteSpace(' ') - PsiElement(>)('>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>)('>') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('2') PsiElement(;)(';') PsiWhiteSpace('\n\n ') MvExprStmtImpl(EXPR_STMT) - MvGreaterExprImpl(GREATER_EXPR) - MvGreaterEqualsExprImpl(GREATER_EQUALS_EXPR) - MvLessExprImpl(LESS_EXPR) - MvLessEqualsExprImpl(LESS_EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[>]) + MvBinaryExprImpl(BINARY_EXPR[>=]) + MvBinaryExprImpl(BINARY_EXPR[<]) + MvBinaryExprImpl(BINARY_EXPR[<=]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('a') PsiWhiteSpace(' ') - PsiElement(<=)('<=') + MvBinaryOpImpl(BINARY_OP) + PsiElement(<=)('<=') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('b') PsiWhiteSpace(' ') - PsiElement(<)('<') + MvBinaryOpImpl(BINARY_OP) + PsiElement(<)('<') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(>=)('>=') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>=)('>=') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('2') PsiWhiteSpace(' ') - PsiElement(>)('>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>)('>') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('3') diff --git a/src/test/resources/org/move/lang/parser/complete/expressions_assignments.txt b/src/test/resources/org/move/lang/parser/complete/expressions_assignments.txt index 416942138..8bb08cd1a 100644 --- a/src/test/resources/org/move/lang/parser/complete/expressions_assignments.txt +++ b/src/test/resources/org/move/lang/parser/complete/expressions_assignments.txt @@ -25,11 +25,12 @@ FILE MvInitializerImpl(INITIALIZER) PsiElement(=)('=') PsiWhiteSpace(' ') - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') @@ -106,13 +107,14 @@ FILE MvInitializerImpl(INITIALIZER) PsiElement(=)('=') PsiWhiteSpace(' ') - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) MvDerefExprImpl(DEREF_EXPR) PsiElement(*)('*') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiWhiteSpace(' ') MvDerefExprImpl(DEREF_EXPR) PsiElement(*)('*') @@ -131,13 +133,14 @@ FILE MvInitializerImpl(INITIALIZER) PsiElement(=)('=') PsiWhiteSpace(' ') - MvMulExprImpl(MUL_EXPR) + MvBinaryExprImpl(BINARY_EXPR[*]) MvDerefExprImpl(DEREF_EXPR) PsiElement(*)('*') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(*)('*') + MvBinaryOpImpl(BINARY_OP) + PsiElement(*)('*') PsiWhiteSpace(' ') MvDerefExprImpl(DEREF_EXPR) PsiElement(*)('*') @@ -156,7 +159,7 @@ FILE MvInitializerImpl(INITIALIZER) PsiElement(=)('=') PsiWhiteSpace(' ') - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) MvDerefExprImpl(DEREF_EXPR) PsiElement(*)('*') MvBangExprImpl(BANG_EXPR) @@ -164,7 +167,8 @@ FILE MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiWhiteSpace(' ') MvDerefExprImpl(DEREF_EXPR) PsiElement(*)('*') diff --git a/src/test/resources/org/move/lang/parser/complete/expressions_specs.txt b/src/test/resources/org/move/lang/parser/complete/expressions_specs.txt index 60d1ece8a..5194b3ab1 100644 --- a/src/test/resources/org/move/lang/parser/complete/expressions_specs.txt +++ b/src/test/resources/org/move/lang/parser/complete/expressions_specs.txt @@ -17,12 +17,13 @@ FILE PsiElement({)('{') PsiWhiteSpace('\n ') MvSpecExprStmtImpl(SPEC_EXPR_STMT) - MvImplyOperatorExprImpl(IMPLY_OPERATOR_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==>]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('a') PsiWhiteSpace(' ') - PsiElement(==>)('==>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==>)('==>') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -30,12 +31,13 @@ FILE PsiElement(;)(';') PsiWhiteSpace('\n ') MvSpecExprStmtImpl(SPEC_EXPR_STMT) - MvPartialImplyOperatorExprImpl(PARTIAL_IMPLY_OPERATOR_EXPR) + MvBinaryExprImpl(BINARY_EXPR[<==>]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('a') PsiWhiteSpace(' ') - PsiElement(<==>)('<==>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(<==>)('<==>') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -43,26 +45,29 @@ FILE PsiElement(;)(';') PsiWhiteSpace('\n ') MvSpecExprStmtImpl(SPEC_EXPR_STMT) - MvImplyOperatorExprImpl(IMPLY_OPERATOR_EXPR) - MvAndExprImpl(AND_EXPR) - MvLessExprImpl(LESS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==>]) + MvBinaryExprImpl(BINARY_EXPR[&&]) + MvBinaryExprImpl(BINARY_EXPR[<]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('a') PsiWhiteSpace(' ') - PsiElement(<)('<') + MvBinaryOpImpl(BINARY_OP) + PsiElement(<)('<') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(&&)('&&') + MvBinaryOpImpl(BINARY_OP) + PsiElement(&&)('&&') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('y') PsiWhiteSpace(' ') - PsiElement(==>)('==>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==>)('==>') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -70,26 +75,29 @@ FILE PsiElement(;)(';') PsiWhiteSpace('\n ') MvSpecExprStmtImpl(SPEC_EXPR_STMT) - MvPartialImplyOperatorExprImpl(PARTIAL_IMPLY_OPERATOR_EXPR) - MvAndExprImpl(AND_EXPR) - MvLessEqualsExprImpl(LESS_EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[<==>]) + MvBinaryExprImpl(BINARY_EXPR[&&]) + MvBinaryExprImpl(BINARY_EXPR[<=]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('a') PsiWhiteSpace(' ') - PsiElement(<=)('<=') + MvBinaryOpImpl(BINARY_OP) + PsiElement(<=)('<=') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(&&)('&&') + MvBinaryOpImpl(BINARY_OP) + PsiElement(&&)('&&') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('y') PsiWhiteSpace(' ') - PsiElement(<==>)('<==>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(<==>)('<==>') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) diff --git a/src/test/resources/org/move/lang/parser/complete/generics.txt b/src/test/resources/org/move/lang/parser/complete/generics.txt index f3d238b08..85b739648 100644 --- a/src/test/resources/org/move/lang/parser/complete/generics.txt +++ b/src/test/resources/org/move/lang/parser/complete/generics.txt @@ -136,7 +136,7 @@ FILE PsiElement(;)(';') PsiWhiteSpace('\n\n ') MvExprStmtImpl(EXPR_STMT) - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('vector') @@ -148,7 +148,8 @@ FILE PsiElement(IDENTIFIER)('u8') PsiElement(>)('>') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -163,7 +164,7 @@ FILE PsiElement(;)(';') PsiWhiteSpace('\n ') MvExprStmtImpl(EXPR_STMT) - MvGreaterEqualsExprImpl(GREATER_EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[>=]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('vector') @@ -175,7 +176,8 @@ FILE PsiElement(IDENTIFIER)('u8') PsiElement(>)('>') PsiWhiteSpace(' ') - PsiElement(>=)('>=') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>=)('>=') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) diff --git a/src/test/resources/org/move/lang/parser/complete/struct_literals.txt b/src/test/resources/org/move/lang/parser/complete/struct_literals.txt index 97625719f..967cb9b46 100644 --- a/src/test/resources/org/move/lang/parser/complete/struct_literals.txt +++ b/src/test/resources/org/move/lang/parser/complete/struct_literals.txt @@ -47,11 +47,12 @@ FILE PsiElement(IDENTIFIER)('b') PsiElement(:)(':') PsiWhiteSpace(' ') - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') @@ -103,11 +104,12 @@ FILE PsiElement(IDENTIFIER)('anotherval') PsiElement(:)(':') PsiWhiteSpace(' ') - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') diff --git a/src/test/resources/org/move/lang/parser/complete/while_loop_inline_assignment.txt b/src/test/resources/org/move/lang/parser/complete/while_loop_inline_assignment.txt index 93f805f16..2ccc8e65b 100644 --- a/src/test/resources/org/move/lang/parser/complete/while_loop_inline_assignment.txt +++ b/src/test/resources/org/move/lang/parser/complete/while_loop_inline_assignment.txt @@ -22,12 +22,13 @@ FILE PsiWhiteSpace(' ') MvConditionImpl(CONDITION) PsiElement(()('(') - MvLessExprImpl(LESS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[<]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('v') PsiWhiteSpace(' ') - PsiElement(<)('<') + MvBinaryOpImpl(BINARY_OP) + PsiElement(<)('<') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('10') @@ -42,12 +43,13 @@ FILE MvInitializerImpl(INITIALIZER) PsiElement(=)('=') PsiWhiteSpace(' ') - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('v') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') @@ -59,12 +61,13 @@ FILE PsiWhiteSpace(' ') MvConditionImpl(CONDITION) PsiElement(()('(') - MvLessExprImpl(LESS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[<]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('v') PsiWhiteSpace(' ') - PsiElement(<)('<') + MvBinaryOpImpl(BINARY_OP) + PsiElement(<)('<') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('10') @@ -81,12 +84,13 @@ FILE MvInitializerImpl(INITIALIZER) PsiElement(=)('=') PsiWhiteSpace(' ') - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('v') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') @@ -100,12 +104,13 @@ FILE PsiWhiteSpace(' ') MvConditionImpl(CONDITION) PsiElement(()('(') - MvLessExprImpl(LESS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[<]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('v') PsiWhiteSpace(' ') - PsiElement(<)('<') + MvBinaryOpImpl(BINARY_OP) + PsiElement(<)('<') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('10') @@ -123,12 +128,13 @@ FILE MvInitializerImpl(INITIALIZER) PsiElement(=)('=') PsiWhiteSpace(' ') - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('v') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') @@ -142,12 +148,13 @@ FILE PsiWhiteSpace(' ') MvConditionImpl(CONDITION) PsiElement(()('(') - MvLessExprImpl(LESS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[<]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('v') PsiWhiteSpace(' ') - PsiElement(<)('<') + MvBinaryOpImpl(BINARY_OP) + PsiElement(<)('<') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('10') @@ -175,12 +182,13 @@ FILE PsiWhiteSpace(' ') MvConditionImpl(CONDITION) PsiElement(()('(') - MvLessExprImpl(LESS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[<]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('v') PsiWhiteSpace(' ') - PsiElement(<)('<') + MvBinaryOpImpl(BINARY_OP) + PsiElement(<)('<') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('10') @@ -200,12 +208,13 @@ FILE MvInitializerImpl(INITIALIZER) PsiElement(=)('=') PsiWhiteSpace(' ') - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('v') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') diff --git a/src/test/resources/org/move/lang/parser/partial/assignments.txt b/src/test/resources/org/move/lang/parser/partial/assignments.txt index 476768454..b3074365a 100644 --- a/src/test/resources/org/move/lang/parser/partial/assignments.txt +++ b/src/test/resources/org/move/lang/parser/partial/assignments.txt @@ -68,21 +68,24 @@ FILE MvAssignmentExprImpl(ASSIGNMENT_EXPR) MvParensExprImpl(PARENS_EXPR) PsiElement(()('(') - MvPlusExprImpl(PLUS_EXPR) - MvPlusExprImpl(PLUS_EXPR) - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) + MvBinaryExprImpl(BINARY_EXPR[+]) + MvBinaryExprImpl(BINARY_EXPR[+]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('a') PsiWhiteSpace(' ') - PsiElement(+)('+') - PsiErrorElement: or '=' expected, got '+' + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') + PsiErrorElement:'+', , or '=' expected, got '+' - PsiElement(+)('+') - PsiErrorElement: or '=' expected, got '+' + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') + PsiErrorElement:'+', , or '=' expected, got '+' - PsiElement(+)('+') - PsiErrorElement:',', ':', , '=' or '[' expected, got ')' + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') + PsiErrorElement:',', ':', , , '=' or '[' expected, got ')' PsiWhiteSpace(' ') PsiElement())(')') @@ -201,7 +204,7 @@ FILE PsiWhiteSpace(' ') MvInitializerImpl(INITIALIZER) PsiElement(=)('=') - PsiErrorElement:',', ':', , '=' or '[' expected, got ')' + PsiErrorElement:',', ':', , , '=' or '[' expected, got ')' PsiWhiteSpace(' ') PsiElement())(')') diff --git a/src/test/resources/org/move/lang/parser/partial/function_calls.txt b/src/test/resources/org/move/lang/parser/partial/function_calls.txt index f544fc3e3..8534d02ea 100644 --- a/src/test/resources/org/move/lang/parser/partial/function_calls.txt +++ b/src/test/resources/org/move/lang/parser/partial/function_calls.txt @@ -36,11 +36,12 @@ FILE MvValueArgumentListImpl(VALUE_ARGUMENT_LIST) PsiElement(()('(') MvValueArgumentImpl(VALUE_ARGUMENT) - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiErrorElement: expected, got ')' PsiElement())(')') @@ -58,11 +59,12 @@ FILE PsiElement(,)(',') PsiWhiteSpace(' ') MvValueArgumentImpl(VALUE_ARGUMENT) - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('2') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiErrorElement: expected, got ')' PsiElement())(')') diff --git a/src/test/resources/org/move/lang/parser/partial/module_const.txt b/src/test/resources/org/move/lang/parser/partial/module_const.txt index adca1eda8..b4e33e59f 100644 --- a/src/test/resources/org/move/lang/parser/partial/module_const.txt +++ b/src/test/resources/org/move/lang/parser/partial/module_const.txt @@ -73,7 +73,7 @@ FILE PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') - PsiErrorElement:'::', ';', '=' or '[' expected, got 'fun' + PsiErrorElement:'::', ';', , '=' or '[' expected, got 'fun' PsiWhiteSpace('\n\n ') MvFunctionImpl(FUNCTION) diff --git a/src/test/resources/org/move/lang/parser/partial/spec.txt b/src/test/resources/org/move/lang/parser/partial/spec.txt index f333ce775..2cb0f60ca 100644 --- a/src/test/resources/org/move/lang/parser/partial/spec.txt +++ b/src/test/resources/org/move/lang/parser/partial/spec.txt @@ -106,7 +106,7 @@ FILE MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiErrorElement:'::', '=' or '[' expected, got '==' + PsiErrorElement:'::', , '=' or '[' expected, got '==' PsiElement(==)('==') PsiElement(>)('>') PsiWhiteSpace(' ') @@ -130,7 +130,7 @@ FILE MvSchemaLitImpl(SCHEMA_LIT) MvPathImpl(PATH) PsiElement(IDENTIFIER)('Schema') - PsiErrorElement:'!', '::', ';', <, '=', '[' or '{' expected, got 'assert' + PsiErrorElement:'!', '::', ';', <, , '=', '[' or '{' expected, got 'assert' PsiWhiteSpace('\n\n ') MvSpecExprStmtImpl(SPEC_EXPR_STMT) @@ -164,12 +164,13 @@ FILE MvEnsuresSpecExprImpl(ENSURES_SPEC_EXPR) PsiElement(ensures_kw)('ensures') PsiWhiteSpace(' ') - MvImplyOperatorExprImpl(IMPLY_OPERATOR_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==>]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('result') PsiWhiteSpace(' ') - PsiElement(==>)('==>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==>)('==>') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') diff --git a/src/test/resources/org/move/lang/parser/specs/conditions.txt b/src/test/resources/org/move/lang/parser/specs/conditions.txt index f8dccf799..0c6e7666f 100644 --- a/src/test/resources/org/move/lang/parser/specs/conditions.txt +++ b/src/test/resources/org/move/lang/parser/specs/conditions.txt @@ -74,12 +74,13 @@ FILE MvInvariantSpecExprImpl(INVARIANT_SPEC_EXPR) PsiElement(invariant_kw)('invariant') PsiWhiteSpace(' ') - MvGreaterExprImpl(GREATER_EXPR) + MvBinaryExprImpl(BINARY_EXPR[>]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(>)('>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>)('>') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('0') @@ -94,12 +95,13 @@ FILE PsiElement(IDENTIFIER)('T') PsiElement(>)('>') PsiWhiteSpace(' ') - MvGreaterExprImpl(GREATER_EXPR) + MvBinaryExprImpl(BINARY_EXPR[>]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(>)('>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>)('>') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('0') @@ -109,12 +111,13 @@ FILE MvAxiomSpecExprImpl(AXIOM_SPEC_EXPR) PsiElement(axiom_kw)('axiom') PsiWhiteSpace(' ') - MvGreaterExprImpl(GREATER_EXPR) + MvBinaryExprImpl(BINARY_EXPR[>]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(>)('>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>)('>') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('0') @@ -129,12 +132,13 @@ FILE PsiElement(IDENTIFIER)('T') PsiElement(>)('>') PsiWhiteSpace(' ') - MvGreaterExprImpl(GREATER_EXPR) + MvBinaryExprImpl(BINARY_EXPR[>]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(>)('>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>)('>') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('0') @@ -144,12 +148,13 @@ FILE MvInvariantSpecExprImpl(INVARIANT_SPEC_EXPR) PsiElement(invariant_kw)('invariant') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -160,7 +165,7 @@ FILE MvInvariantSpecExprImpl(INVARIANT_SPEC_EXPR) PsiElement(invariant_kw)('invariant') PsiWhiteSpace(' ') - MvLessExprImpl(LESS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[<]) MvDotExprImpl(DOT_EXPR) MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) @@ -183,7 +188,8 @@ FILE MvStructDotFieldImpl(STRUCT_DOT_FIELD) PsiElement(IDENTIFIER)('value') PsiWhiteSpace(' ') - PsiElement(<)('<') + MvBinaryOpImpl(BINARY_OP) + PsiElement(<)('<') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('128') @@ -195,7 +201,7 @@ FILE PsiWhiteSpace(' ') PsiElement(update_kw)('update') PsiWhiteSpace(' ') - MvLessExprImpl(LESS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[<]) MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('old') @@ -207,7 +213,8 @@ FILE PsiElement(IDENTIFIER)('y') PsiElement())(')') PsiWhiteSpace(' ') - PsiElement(<)('<') + MvBinaryOpImpl(BINARY_OP) + PsiElement(<)('<') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -228,13 +235,14 @@ FILE MvInitializerImpl(INITIALIZER) PsiElement(=)('=') PsiWhiteSpace(' ') - MvPlusExprImpl(PLUS_EXPR) - MvMinusExprImpl(MINUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) + MvBinaryExprImpl(BINARY_EXPR[-]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('expected_coin_sum') PsiWhiteSpace(' ') - PsiElement(-)('-') + MvBinaryOpImpl(BINARY_OP) + PsiElement(-)('-') PsiWhiteSpace(' ') MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) @@ -247,7 +255,8 @@ FILE PsiElement(IDENTIFIER)('x') PsiElement())(')') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -268,12 +277,13 @@ FILE MvInitializerImpl(INITIALIZER) PsiElement(=)('=') PsiWhiteSpace(' ') - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('expected_coin_sum') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -294,12 +304,13 @@ FILE MvInitializerImpl(INITIALIZER) PsiElement(=)('=') PsiWhiteSpace(' ') - MvMinusExprImpl(MINUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[-]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('expected_coin_sum') PsiWhiteSpace(' ') - PsiElement(-)('-') + MvBinaryOpImpl(BINARY_OP) + PsiElement(-)('-') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -317,12 +328,13 @@ FILE PsiElement(IDENTIFIER)('global') PsiElement(])(']') PsiWhiteSpace(' ') - MvGreaterExprImpl(GREATER_EXPR) + MvBinaryExprImpl(BINARY_EXPR[>]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(>)('>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>)('>') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('0') @@ -343,12 +355,13 @@ FILE PsiElement(IDENTIFIER)('isolated') PsiElement(])(']') PsiWhiteSpace(' ') - MvGreaterExprImpl(GREATER_EXPR) + MvBinaryExprImpl(BINARY_EXPR[>]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(>)('>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>)('>') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('0') @@ -373,12 +386,13 @@ FILE PsiElement(IDENTIFIER)('deactivated') PsiElement(])(']') PsiWhiteSpace(' ') - MvGreaterExprImpl(GREATER_EXPR) + MvBinaryExprImpl(BINARY_EXPR[>]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(>)('>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>)('>') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('0') @@ -397,12 +411,13 @@ FILE PsiElement(IDENTIFIER)('global') PsiElement(])(']') PsiWhiteSpace(' ') - MvGreaterExprImpl(GREATER_EXPR) + MvBinaryExprImpl(BINARY_EXPR[>]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(>)('>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>)('>') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('0') @@ -412,12 +427,13 @@ FILE MvAbortsIfSpecExprImpl(ABORTS_IF_SPEC_EXPR) PsiElement(aborts_if_kw)('aborts_if') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('0') @@ -427,12 +443,13 @@ FILE MvAbortsIfSpecExprImpl(ABORTS_IF_SPEC_EXPR) PsiElement(aborts_if_kw)('aborts_if') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('y') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('0') @@ -442,11 +459,12 @@ FILE MvAbortsIfSpecExprImpl(ABORTS_IF_SPEC_EXPR) PsiElement(aborts_if_kw)('aborts_if') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('0') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -467,19 +485,21 @@ FILE MvEnsuresSpecExprImpl(ENSURES_SPEC_EXPR) PsiElement(ensures_kw)('ensures') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('RET') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') @@ -489,18 +509,20 @@ FILE MvEnsuresSpecExprImpl(ENSURES_SPEC_EXPR) PsiElement(ensures_kw)('ensures') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('RET') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') - MvDivExprImpl(DIV_EXPR) + MvBinaryExprImpl(BINARY_EXPR[/]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') - PsiElement(/)('/') + MvBinaryOpImpl(BINARY_OP) + PsiElement(/)('/') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('y') @@ -510,17 +532,19 @@ FILE MvEnsuresSpecExprImpl(ENSURES_SPEC_EXPR) PsiElement(ensures_kw)('ensures') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) - MvDivExprImpl(DIV_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) + MvBinaryExprImpl(BINARY_EXPR[/]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') - PsiElement(/)('/') + MvBinaryOpImpl(BINARY_OP) + PsiElement(/)('/') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('y') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -531,12 +555,13 @@ FILE MvEnsuresSpecExprImpl(ENSURES_SPEC_EXPR) PsiElement(ensures_kw)('ensures') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('RET') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvCodeBlockExprImpl(CODE_BLOCK_EXPR) MvCodeBlockImpl(CODE_BLOCK) @@ -555,12 +580,13 @@ FILE PsiElement(IDENTIFIER)('x') PsiElement(;)(';') PsiWhiteSpace(' ') - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('y') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') @@ -591,19 +617,21 @@ FILE PsiElement(IDENTIFIER)('z') PsiElement(|)('|') PsiWhiteSpace(' ') - MvPlusExprImpl(PLUS_EXPR) - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) + MvBinaryExprImpl(BINARY_EXPR[+]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('y') PsiWhiteSpace(' ') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -615,13 +643,14 @@ FILE MvEnsuresSpecExprImpl(ENSURES_SPEC_EXPR) PsiElement(ensures_kw)('ensures') PsiWhiteSpace(' ') - MvAndExprImpl(AND_EXPR) - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[&&]) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('RET') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvIndexExprImpl(INDEX_EXPR) MvRefExprImpl(REF_EXPR) @@ -632,7 +661,8 @@ FILE PsiElement(INTEGER_LITERAL)('1') PsiElement(])(']') PsiWhiteSpace(' ') - PsiElement(&&)('&&') + MvBinaryOpImpl(BINARY_OP) + PsiElement(&&)('&&') PsiWhiteSpace(' ') MvIndexExprImpl(INDEX_EXPR) MvRefExprImpl(REF_EXPR) @@ -653,32 +683,36 @@ FILE MvEnsuresSpecExprImpl(ENSURES_SPEC_EXPR) PsiElement(ensures_kw)('ensures') PsiWhiteSpace(' ') - MvImplyOperatorExprImpl(IMPLY_OPERATOR_EXPR) - MvGreaterExprImpl(GREATER_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==>]) + MvBinaryExprImpl(BINARY_EXPR[>]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(>)('>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>)('>') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('0') PsiWhiteSpace(' ') - PsiElement(==>)('==>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==>)('==>') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('RET') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') - MvMinusExprImpl(MINUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[-]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(-)('-') + MvBinaryOpImpl(BINARY_OP) + PsiElement(-)('-') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') @@ -688,25 +722,28 @@ FILE MvEnsuresSpecExprImpl(ENSURES_SPEC_EXPR) PsiElement(ensures_kw)('ensures') PsiWhiteSpace(' ') - MvImplyOperatorExprImpl(IMPLY_OPERATOR_EXPR) - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==>]) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('0') PsiWhiteSpace(' ') - PsiElement(==>)('==>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==>)('==>') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('RET') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -717,7 +754,7 @@ FILE MvEnsuresSpecExprImpl(ENSURES_SPEC_EXPR) PsiElement(ensures_kw)('ensures') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('generic') @@ -729,7 +766,8 @@ FILE PsiElement(IDENTIFIER)('T') PsiElement(>)('>') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') @@ -739,7 +777,7 @@ FILE MvEnsuresSpecExprImpl(ENSURES_SPEC_EXPR) PsiElement(ensures_kw)('ensures') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) MvModuleRefImpl(MODULE_REF) @@ -754,7 +792,8 @@ FILE PsiElement(IDENTIFIER)('T') PsiElement(>)('>') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') @@ -777,7 +816,7 @@ FILE MvQuantWhereImpl(QUANT_WHERE) PsiElement(where_kw)('where') PsiWhiteSpace(' ') - MvAndExprImpl(AND_EXPR) + MvBinaryExprImpl(BINARY_EXPR[&&]) MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('exists') @@ -796,9 +835,10 @@ FILE PsiElement(IDENTIFIER)('a') PsiElement())(')') PsiWhiteSpace(' ') - PsiElement(&&)('&&') + MvBinaryOpImpl(BINARY_OP) + PsiElement(&&)('&&') PsiWhiteSpace(' ') - MvGreaterExprImpl(GREATER_EXPR) + MvBinaryExprImpl(BINARY_EXPR[>]) MvDotExprImpl(DOT_EXPR) MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) @@ -821,7 +861,8 @@ FILE MvStructDotFieldImpl(STRUCT_DOT_FIELD) PsiElement(IDENTIFIER)('value') PsiWhiteSpace(' ') - PsiElement(>)('>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>)('>') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('0') @@ -846,7 +887,7 @@ FILE MvQuantWhereImpl(QUANT_WHERE) PsiElement(where_kw)('where') PsiWhiteSpace(' ') - MvAndExprImpl(AND_EXPR) + MvBinaryExprImpl(BINARY_EXPR[&&]) MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('in_range') @@ -864,9 +905,10 @@ FILE PsiElement(IDENTIFIER)('i') PsiElement())(')') PsiWhiteSpace(' ') - PsiElement(&&)('&&') + MvBinaryOpImpl(BINARY_OP) + PsiElement(&&)('&&') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvIndexExprImpl(INDEX_EXPR) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -877,7 +919,8 @@ FILE PsiElement(IDENTIFIER)('i') PsiElement(])(']') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('2') @@ -918,7 +961,7 @@ FILE MvQuantWhereImpl(QUANT_WHERE) PsiElement(where_kw)('where') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvDotExprImpl(DOT_EXPR) MvIndexExprImpl(INDEX_EXPR) MvRefExprImpl(REF_EXPR) @@ -933,7 +976,8 @@ FILE MvStructDotFieldImpl(STRUCT_DOT_FIELD) PsiElement(IDENTIFIER)('id') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -990,7 +1034,7 @@ FILE MvQuantWhereImpl(QUANT_WHERE) PsiElement(where_kw)('where') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvDotExprImpl(DOT_EXPR) MvIndexExprImpl(INDEX_EXPR) MvRefExprImpl(REF_EXPR) @@ -1005,7 +1049,8 @@ FILE MvStructDotFieldImpl(STRUCT_DOT_FIELD) PsiElement(IDENTIFIER)('id') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -1036,7 +1081,7 @@ FILE MvRequiresSpecExprImpl(REQUIRES_SPEC_EXPR) PsiElement(requires_kw)('requires') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvDotExprImpl(DOT_EXPR) MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) @@ -1058,7 +1103,8 @@ FILE MvStructDotFieldImpl(STRUCT_DOT_FIELD) PsiElement(IDENTIFIER)('f') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvDotExprImpl(DOT_EXPR) MvCallExprImpl(CALL_EXPR) @@ -1086,7 +1132,7 @@ FILE MvEnsuresSpecExprImpl(ENSURES_SPEC_EXPR) PsiElement(ensures_kw)('ensures') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvDotExprImpl(DOT_EXPR) MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) @@ -1108,7 +1154,8 @@ FILE MvStructDotFieldImpl(STRUCT_DOT_FIELD) PsiElement(IDENTIFIER)('f') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvDotExprImpl(DOT_EXPR) MvCallExprImpl(CALL_EXPR) diff --git a/src/test/resources/org/move/lang/parser/specs/forall_exists.txt b/src/test/resources/org/move/lang/parser/specs/forall_exists.txt index 449a98ca1..f10b1057b 100644 --- a/src/test/resources/org/move/lang/parser/specs/forall_exists.txt +++ b/src/test/resources/org/move/lang/parser/specs/forall_exists.txt @@ -42,12 +42,13 @@ FILE PsiElement(INTEGER_LITERAL)('100') PsiElement(:)(':') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('i') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('3') @@ -152,40 +153,45 @@ FILE PsiWhiteSpace('\n ') PsiElement(:)(':') PsiWhiteSpace(' ') - MvImplyOperatorExprImpl(IMPLY_OPERATOR_EXPR) - MvAndExprImpl(AND_EXPR) - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==>]) + MvBinaryExprImpl(BINARY_EXPR[&&]) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('y') PsiWhiteSpace(' ') - PsiElement(&&)('&&') + MvBinaryOpImpl(BINARY_OP) + PsiElement(&&)('&&') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('y') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('z') PsiWhiteSpace(' ') - PsiElement(==>)('==>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==>)('==>') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -226,12 +232,13 @@ FILE PsiWhiteSpace('\n ') PsiElement(:)(':') PsiWhiteSpace(' ') - MvGreaterEqualsExprImpl(GREATER_EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[>=]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('y') PsiWhiteSpace(' ') - PsiElement(>=)('>=') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>=)('>=') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -282,12 +289,13 @@ FILE PsiElement(BOOL_LITERAL)('false') PsiElement(:)(':') PsiWhiteSpace('\n ') - MvGreaterEqualsExprImpl(GREATER_EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[>=]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(>=)('>=') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>=)('>=') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -333,12 +341,13 @@ FILE PsiWhiteSpace(' ') PsiElement(:)(':') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -384,12 +393,13 @@ FILE PsiWhiteSpace(' ') PsiElement(:)(':') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -400,12 +410,13 @@ FILE MvEnsuresSpecExprImpl(ENSURES_SPEC_EXPR) PsiElement(ensures_kw)('ensures') PsiWhiteSpace(' ') - MvImplyOperatorExprImpl(IMPLY_OPERATOR_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==>]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('result') PsiWhiteSpace(' ') - PsiElement(==>)('==>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==>)('==>') PsiWhiteSpace(' ') MvParensExprImpl(PARENS_EXPR) PsiElement(()('(') @@ -457,12 +468,13 @@ FILE PsiWhiteSpace(' ') PsiElement(:)(':') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') diff --git a/src/test/resources/org/move/lang/parser/specs/spec_statements.txt b/src/test/resources/org/move/lang/parser/specs/spec_statements.txt index 1ff796974..8113b17d9 100644 --- a/src/test/resources/org/move/lang/parser/specs/spec_statements.txt +++ b/src/test/resources/org/move/lang/parser/specs/spec_statements.txt @@ -77,7 +77,7 @@ FILE MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiErrorElement:'::', '=' or '[' expected, got '==' + PsiErrorElement:'::', , '=' or '[' expected, got '==' PsiElement(==)('==') PsiElement(>)('>') PsiWhiteSpace(' ') @@ -124,20 +124,22 @@ FILE PsiElement(INTEGER_LITERAL)('1') PsiElement(.)('.') PsiElement(.)('.') - MvPlusExprImpl(PLUS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[+]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') - PsiElement(+)('+') + MvBinaryOpImpl(BINARY_OP) + PsiElement(+)('+') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiElement(;)(';') PsiWhiteSpace('\n ') MvSpecExprStmtImpl(SPEC_EXPR_STMT) - MvImplyOperatorExprImpl(IMPLY_OPERATOR_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==>]) MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiElement(==>)('==>') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==>)('==>') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('2') @@ -191,12 +193,13 @@ FILE PsiElement(IDENTIFIER)('concrete') PsiElement(])(']') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('result') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') @@ -213,12 +216,13 @@ FILE PsiElement(IDENTIFIER)('global') PsiElement(])(']') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('result') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') @@ -369,12 +373,13 @@ FILE MvEnsuresSpecExprImpl(ENSURES_SPEC_EXPR) PsiElement(ensures_kw)('ensures') PsiWhiteSpace(' ') - MvEqualsExprImpl(EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[==]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('result') PsiWhiteSpace(' ') - PsiElement(==)('==') + MvBinaryOpImpl(BINARY_OP) + PsiElement(==)('==') PsiWhiteSpace(' ') MvCallExprImpl(CALL_EXPR) MvPathImpl(PATH) @@ -398,25 +403,28 @@ FILE MvQuantWhereImpl(QUANT_WHERE) PsiElement(where_kw)('where') PsiWhiteSpace(' ') - MvAndExprImpl(AND_EXPR) - MvGreaterEqualsExprImpl(GREATER_EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[&&]) + MvBinaryExprImpl(BINARY_EXPR[>=]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(>=)('>=') + MvBinaryOpImpl(BINARY_OP) + PsiElement(>=)('>=') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('4') PsiWhiteSpace(' ') - PsiElement(&&)('&&') + MvBinaryOpImpl(BINARY_OP) + PsiElement(&&)('&&') PsiWhiteSpace(' ') - MvLessEqualsExprImpl(LESS_EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[<=]) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) PsiElement(IDENTIFIER)('x') PsiWhiteSpace(' ') - PsiElement(<=)('<=') + MvBinaryOpImpl(BINARY_OP) + PsiElement(<=)('<=') PsiWhiteSpace(' ') MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('5') @@ -514,7 +522,7 @@ FILE MvIncludeStmtImpl(INCLUDE_STMT) PsiElement(include_kw)('include') PsiWhiteSpace(' ') - MvNotEqualsExprImpl(NOT_EQUALS_EXPR) + MvBinaryExprImpl(BINARY_EXPR[!=]) MvDotExprImpl(DOT_EXPR) MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -523,7 +531,8 @@ FILE MvStructDotFieldImpl(STRUCT_DOT_FIELD) PsiElement(IDENTIFIER)('agree') PsiWhiteSpace(' ') - PsiElement(!=)('!=') + MvBinaryOpImpl(BINARY_OP) + PsiElement(!=)('!=') PsiWhiteSpace(' ') MvRefExprImpl(REF_EXPR) MvPathImpl(PATH) @@ -641,7 +650,7 @@ FILE MvLitExprImpl(LIT_EXPR) PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace(' ') - PsiErrorElement:'::', '=' or '[' expected, got '==' + PsiErrorElement:'::', , '=' or '[' expected, got '==' PsiElement(==)('==') PsiElement(>)('>') PsiWhiteSpace(' ') From a2cecb73c8173e0ecbae27e4b20be045a3c70d4f Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Fri, 16 Sep 2022 22:38:46 +0200 Subject: [PATCH 09/26] rework some type inference parts --- .../ide/inspections/MvTypeCheckInspection.kt | 24 ------- .../core/psi/ext/MoveStructLiteralField.kt | 7 -- .../move/lang/core/psi/ext/MvBindingPat.kt | 21 +++--- .../org/move/lang/core/psi/ext/MvStructPat.kt | 6 ++ .../lang/core/types/infer/ConstraintSolver.kt | 6 +- .../lang/core/types/infer/ExpectedType.kt | 21 +++--- .../move/lang/core/types/infer/Expressions.kt | 62 ++++++++++++++++-- .../lang/core/types/infer/InferenceContext.kt | 20 ++++-- .../move/lang/core/types/infer/Patterns.kt | 64 ++++++++++++++++--- .../lang/core/types/infer/TypeDeclarations.kt | 10 ++- .../org/move/lang/core/types/ty/TyStruct.kt | 15 +---- .../FieldInitShorthandInspectionTest.kt | 4 ++ .../inspections/MvTypeCheckInspectionTest.kt | 25 ++++---- .../lang/completion/KeywordCompletionTest.kt | 16 +++++ .../org/move/lang/types/ExpectedTypeTest.kt | 49 ++++++++++++++ .../lang/types/ExpressionTypeInferenceTest.kt | 33 ++++++++++ 16 files changed, 280 insertions(+), 103 deletions(-) create mode 100644 src/main/kotlin/org/move/lang/core/psi/ext/MvStructPat.kt diff --git a/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt b/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt index 0310cc433..800fb404b 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt @@ -55,30 +55,6 @@ class MvTypeCheckInspection : MvLocalInspectionTool() { .forEach { holder.registerTypeError(it) } } - override fun visitStructLitExpr(litExpr: MvStructLitExpr) { - val struct = litExpr.path.maybeStruct ?: return - - val msl = litExpr.isMsl() - val ctx = litExpr.functionInferenceCtx(msl) - for (field in litExpr.fields) { - val initExprTy = inferLitFieldInitExprTy(field, ctx) - - val fieldName = field.referenceName - val fieldDef = struct.getField(fieldName) ?: continue - val expectedFieldTy = fieldDef.declaredTy(msl) - - if (!isCompatible(expectedFieldTy, initExprTy)) { - val exprTypeName = initExprTy.name() - val expectedTypeName = expectedFieldTy.name() - val message = - "Invalid argument for field '$fieldName': " + - "type '$exprTypeName' is not compatible with '$expectedTypeName'" - val initExpr = field.expr ?: field - holder.registerTypeError(initExpr, message) - } - } - } - override fun visitValueArgumentList(callArgs: MvValueArgumentList) { val callExpr = callArgs.parent as? MvCallExpr ?: return val function = callExpr.path.reference?.resolve() as? MvFunctionLike ?: return diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MoveStructLiteralField.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MoveStructLiteralField.kt index 05a8a609b..2142d2ad8 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MoveStructLiteralField.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MoveStructLiteralField.kt @@ -21,13 +21,6 @@ val MvStructLitField.structLitExpr: MvStructLitExpr val MvStructLitField.isShorthand: Boolean get() = !hasChild(MvElementTypes.COLON) -fun MvStructLitField.ty(): Ty { - val msl = this.isMsl() - val ctx = this.containingFunction?.inferenceCtx(msl) ?: return TyUnknown - val structLitTy = inferStructLitExpr(this.structLitExpr, ctx) as? TyStruct ?: return TyUnknown - return structLitTy.fieldTy(this.referenceName, msl) -} - abstract class MvStructLitFieldMixin(node: ASTNode) : MvElementImpl(node), MvStructLitField { override fun getReference(): MvReference { diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvBindingPat.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvBindingPat.kt index 224d9ca31..b32af6bfc 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvBindingPat.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvBindingPat.kt @@ -25,29 +25,26 @@ val MvBindingPat.owner: PsiElement? || it is MvSchemaFieldStmt } -fun MvBindingPat.declaredTy(parentCtx: InferenceContext): Ty { +fun MvBindingPat.declaredTy(parentCtx: InferenceContext): Ty? { val owner = this.owner return when (owner) { is MvFunctionParameter -> owner.declaredTy(parentCtx.msl) is MvConst -> owner.declaredTy(parentCtx.msl) + is MvSchemaFieldStmt -> owner.declaredTy(parentCtx.msl) is MvLetStmt -> { - if (parentCtx.bindingTypes.containsKey(this)) return parentCtx.bindingTypes[this]!! - - val pat = owner.pat ?: return TyUnknown - val explicitType = owner.typeAnnotation?.type - if (explicitType != null) { - val explicitTy = inferTypeTy(explicitType, parentCtx.msl) - collectBindings(pat, explicitTy, parentCtx) - return parentCtx.bindingTypes[this] ?: TyUnknown - } - return TyUnknown + val explicitType = owner.typeAnnotation?.type ?: return null + val typeTy = inferTypeTy(explicitType, parentCtx.msl) + parentCtx.resolveTy(typeTy) } - is MvSchemaFieldStmt -> owner.declaredTy(parentCtx.msl) else -> TyUnknown } } fun MvBindingPat.inferredTy(parentCtx: InferenceContext): Ty { + val existingTy = parentCtx.bindingTypes[this] + if (existingTy != null) { + return existingTy + } val owner = this.owner return when (owner) { is MvFunctionParameter -> owner.declaredTy(parentCtx.msl) diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvStructPat.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvStructPat.kt new file mode 100644 index 000000000..a4be0360e --- /dev/null +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvStructPat.kt @@ -0,0 +1,6 @@ +package org.move.lang.core.psi.ext + +import org.move.lang.core.psi.MvStruct +import org.move.lang.core.psi.MvStructPat + +val MvStructPat.struct: MvStruct? get() = this.path.reference?.resolve() as? MvStruct diff --git a/src/main/kotlin/org/move/lang/core/types/infer/ConstraintSolver.kt b/src/main/kotlin/org/move/lang/core/types/infer/ConstraintSolver.kt index 171745e0a..2cb4e0829 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/ConstraintSolver.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/ConstraintSolver.kt @@ -27,13 +27,15 @@ class ConstraintSolver(val ctx: InferenceContext) { while (constraints.isNotEmpty()) { val constraint = constraints.removeFirst() val isSuccessful = processConstraint(constraint) - if (!isSuccessful) solvable = false + if (!isSuccessful) { + solvable = false + } } return solvable } private fun processConstraint(rawConstraint: EqualityConstraint): Boolean { - val constraint = rawConstraint.foldTyInferWith(ctx::resolveTyInferFromContext) + val constraint = rawConstraint.foldTyInferWith(ctx::resolveTyInfer) var ty1 = constraint.ty1 var ty2 = constraint.ty2 if (ctx.msl) { diff --git a/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt b/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt index f5006bc08..e94463e85 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt @@ -4,6 +4,7 @@ import com.intellij.psi.PsiElement import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.declaredTy import org.move.lang.core.psi.ext.isMsl +import org.move.lang.core.psi.ext.structLitExpr import org.move.lang.core.psi.ext.ty import org.move.lang.core.types.ty.Ty import org.move.lang.core.types.ty.TyReference @@ -56,20 +57,20 @@ fun inferExpectedTy(element: PsiElement, ctx: InferenceContext): Ty? { val initializerParent = owner.parent when (initializerParent) { is MvLetStmt -> { - val pat = initializerParent.pat - when (pat) { - is MvBindingPat -> { - val ty = pat.declaredTy(ctx) - if (ty is TyUnknown) null else ty - } - is MvStructPat -> pat.ty() - else -> null - } + val patExplicitTy = initializerParent.typeAnnotation?.type?.let { inferTypeTy(it, ctx.msl) } + initializerParent.pat + ?.let { inferPatTy(it, ctx, patExplicitTy) } } else -> null } } - is MvStructLitField -> owner.ty() + is MvStructLitField -> { + // only first level field for now, rewrite later as recursive + val structLitExpr = owner.structLitExpr + val structExpectedTy = inferExpectedTy(structLitExpr, ctx) + val structTy = inferExprTy(structLitExpr, ctx, structExpectedTy) as? TyStruct ?: return null + structTy.fieldTy(owner.referenceName) + } else -> null } } diff --git a/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt b/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt index 543663f29..7313edcc6 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt @@ -161,7 +161,7 @@ private fun inferDotExprTy(dotExpr: MvDotExpr, parentCtx: InferenceContext): Ty if (!inferenceCtx.processConstraints()) return TyUnknown val fieldName = dotExpr.structDotField.referenceName - return inferenceCtx.resolveTy(structTy.fieldTy(fieldName, parentCtx.msl)) + return inferenceCtx.resolveTy(structTy.fieldTy(fieldName)) } fun inferStructLitExpr( @@ -202,8 +202,7 @@ fun inferStructLitExpr( for (field in litExpr.fields) { val fieldName = field.referenceName val fieldTy = structTy.fieldTys[fieldName] ?: TyUnknown - val fieldInitExprTy = inferLitFieldInitExprTy(field, parentCtx) - inferenceCtx.addConstraint(fieldTy, fieldInitExprTy) + inferLitFieldInitExprTy(field, parentCtx, fieldTy) } if (expectedTy != null) { inferenceCtx.addConstraint(structTy, expectedTy) @@ -214,21 +213,72 @@ fun inferStructLitExpr( return inferenceCtx.resolveTy(structTy) } +fun inferStructPatTy(structPat: MvStructPat, parentCtx: InferenceContext, expectedTy: Ty?): Ty { + val path = structPat.path + val struct = structPat.struct ?: return TyUnknown + val structTy = instantiateItemTy(struct, parentCtx.msl) as TyStruct + + val inferenceCtx = InferenceContext(parentCtx.msl) + // find all types passed as explicit type parameters, create constraints with those + if (path.typeArguments.isNotEmpty()) { + if (path.typeArguments.size != structTy.typeVars.size) return TyUnknown + for ((typeVar, typeArg) in structTy.typeVars.zip(path.typeArguments)) { + val typeArgTy = inferTypeTy(typeArg.type, parentCtx.msl) + + // check compat for abilities + val compat = isCompatibleAbilities(typeVar, typeArgTy, path.isMsl()) + val isCompat = when (compat) { + is Compat.AbilitiesMismatch -> { + parentCtx.typeErrors.add( + TypeError.AbilitiesMismatch( + typeArg, + typeArgTy, + compat.abilities + ) + ) + false + } + + else -> true + } + inferenceCtx.addConstraint(typeVar, if (isCompat) typeArgTy else TyUnknown) + } + } + if (expectedTy != null) { + if (isCompatible(expectedTy, structTy)) { + inferenceCtx.addConstraint(structTy, expectedTy) + } else { + parentCtx.typeErrors.add(TypeError.InvalidUnpacking(structPat, expectedTy)) + } + } + inferenceCtx.processConstraints() + parentCtx.resolveTyVarsFromContext(inferenceCtx) + return inferenceCtx.resolveTy(structTy) +} + fun inferVectorLitExpr(litExpr: MvVectorLitExpr, parentCtx: InferenceContext): Ty { return TyVector(TyUnknown) } -fun inferLitFieldInitExprTy(litField: MvStructLitField, ctx: InferenceContext): Ty { +fun inferLitFieldInitExprTy(litField: MvStructLitField, ctx: InferenceContext, expectedTy: Ty?): Ty { val initExpr = litField.expr return if (initExpr == null) { // find type of binding val binding = litField.reference.multiResolve().filterIsInstance().firstOrNull() ?: return TyUnknown - binding.inferredTy(ctx) + val bindingTy = binding.inferredTy(ctx) + if (expectedTy != null) { + if (!isCompatible(expectedTy, bindingTy, ctx.msl)) { + ctx.typeErrors.add(TypeError.TypeMismatch(litField, expectedTy, bindingTy)) + } else { + ctx.addConstraint(bindingTy, expectedTy) + } + } + bindingTy } else { // find type of expression - inferExprTy(initExpr, ctx) + inferExprTy(initExpr, ctx, expectedTy) } } diff --git a/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt b/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt index 5b25d7b64..03d73bb87 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt @@ -52,10 +52,11 @@ fun inferCodeBlockTy(block: MvCodeBlock, blockCtx: InferenceContext, expectedTy: when (stmt) { is MvExprStmt -> inferExprTy(stmt.expr, blockCtx) is MvLetStmt -> { - val explicitTy = stmt.declaredTy +// val explicitTy = stmt.declaredTy + val explicitTy = stmt.typeAnnotation?.type?.let { inferTypeTy(it, stmt.isMsl()) } val initializerTy = stmt.initializer?.expr?.let { inferExprTy(it, blockCtx, explicitTy) } - val patTy = explicitTy ?: initializerTy ?: TyUnknown val pat = stmt.pat ?: continue + val patTy = inferPatTy(pat, blockCtx, explicitTy ?: initializerTy) collectBindings(pat, patTy, blockCtx) } } @@ -314,8 +315,9 @@ sealed class TypeError(open val element: PsiElement) { } } -class InferenceContext(var msl: Boolean) { +class InferenceContext(val msl: Boolean) { var exprTypes = concurrentMapOf() + val patTypes = mutableMapOf() var callExprTypes = mutableMapOf() val bindingTypes = concurrentMapOf() var typeErrors = mutableListOf() @@ -337,6 +339,10 @@ class InferenceContext(var msl: Boolean) { this.exprTypes[expr] = ty } + fun cachePatTy(pat: MvPat, ty: Ty) { + this.patTypes[pat] = ty + } + fun cacheCallExprTy(expr: MvCallExpr, ty: TyFunction) { this.callExprTypes[expr] = ty } @@ -351,14 +357,14 @@ class InferenceContext(var msl: Boolean) { } fun resolveTy(ty: Ty): Ty { - return ty.foldTyInferWith(this::resolveTyInferFromContext) + return ty.foldTyInferWith(this::resolveTyInfer) } - fun resolveTyInferFromContext(ty: Ty): Ty { + fun resolveTyInfer(ty: Ty): Ty { if (ty !is TyInfer) return ty return when (ty) { - is TyInfer.TyVar -> unificationTable.findValue(ty)?.let(this::resolveTyInferFromContext) ?: ty - is TyInfer.IntVar -> intUnificationTable.findValue(ty)?.let(this::resolveTyInferFromContext) ?: ty + is TyInfer.TyVar -> unificationTable.findValue(ty)?.let(this::resolveTyInfer) ?: ty + is TyInfer.IntVar -> intUnificationTable.findValue(ty)?.let(this::resolveTyInfer) ?: ty } } diff --git a/src/main/kotlin/org/move/lang/core/types/infer/Patterns.kt b/src/main/kotlin/org/move/lang/core/types/infer/Patterns.kt index e76620c6e..85017ed30 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/Patterns.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/Patterns.kt @@ -11,6 +11,42 @@ import org.move.lang.core.types.ty.TyStruct import org.move.lang.core.types.ty.TyTuple import org.move.lang.core.types.ty.TyUnknown +fun inferPatTy(pat: MvPat, parentCtx: InferenceContext, expectedTy: Ty? = null): Ty { + val existingTy = parentCtx.patTypes[pat] + if (existingTy != null) { + return existingTy + } + val patTy = when (pat) { + is MvStructPat -> inferStructPatTy(pat, parentCtx, expectedTy) + is MvTuplePat -> { + val tupleTy = TyTuple(pat.patList.map { TyUnknown }) + if (expectedTy != null) { + if (expectedTy is TyTuple && isCompatible(expectedTy, tupleTy)) { + val itemTys = pat.patList.mapIndexed { i, itemPat -> + inferPatTy( + itemPat, + parentCtx, + expectedTy.types[i] + ) + } + return TyTuple(itemTys) + } else { + parentCtx.typeErrors.add(TypeError.InvalidUnpacking(pat, expectedTy)) + } + } + TyUnknown + } + is MvBindingPat -> { + val ty = expectedTy ?: TyUnknown + parentCtx.bindingTypes[pat] = ty + ty + } + else -> TyUnknown + } + parentCtx.cachePatTy(pat, patTy) + return patTy +} + fun collectBindings(pattern: MvPat, inferredTy: Ty, parentCtx: InferenceContext) { fun bind(pat: MvPat, ty: Ty) { when (pat) { @@ -22,23 +58,33 @@ fun collectBindings(pattern: MvPat, inferredTy: Ty, parentCtx: InferenceContext) pat.patList.zip(ty.types) .forEach { (pat, ty) -> bind(pat, ty) } } else { - if (ty !is TyUnknown) { - parentCtx.typeErrors.add(TypeError.InvalidUnpacking(pat, ty)) - } pat.patList.map { bind(it, TyUnknown) } } } is MvStructPat -> { - if (ty is TyStruct && pat.fields.size == ty.fieldsTy().size) { - val fieldsTy = ty.fieldsTy() + val patTy = inferPatTy(pat, parentCtx, ty) + when (patTy) { + is TyStruct -> { + when { + ty is TyUnknown -> pat.fields.map { + it.pat?.let { pat -> bind(pat, TyUnknown) } + } + ty is TyStruct && pat.fields.size == ty.fieldTys.size -> { + for (field in pat.fields) { + val fieldTy = ty.fieldTys[field.referenceName] ?: TyUnknown + field.pat?.let { bind(it, fieldTy) } + } + } + } + } + else -> bind(pat, TyUnknown) + } + if (ty is TyStruct && pat.fields.size == ty.fieldTys.size) { for (field in pat.fields) { - val fieldTy = fieldsTy[field.referenceName] ?: TyUnknown + val fieldTy = ty.fieldTys[field.referenceName] ?: TyUnknown field.pat?.let { bind(it, fieldTy) } } } else { - if (ty !is TyUnknown) { - parentCtx.typeErrors.add(TypeError.InvalidUnpacking(pat, ty)) - } pat.fields.map { it.pat?.let { pat -> bind(pat, TyUnknown) } } diff --git a/src/main/kotlin/org/move/lang/core/types/infer/TypeDeclarations.kt b/src/main/kotlin/org/move/lang/core/types/infer/TypeDeclarations.kt index 0b4e3410e..76b059776 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/TypeDeclarations.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/TypeDeclarations.kt @@ -35,8 +35,14 @@ fun inferTypeTy(moveType: MvType, msl: Boolean): Ty { is MvStruct -> { val typeArgs = moveType.path.typeArguments.map { inferTypeTy(it.type, msl) } val structTy = instantiateItemTy(struct, msl) as? TyStruct ?: return TyUnknown - structTy.typeArgs = typeArgs - structTy + + val ctx = InferenceContext(msl) + for ((tyVar, tyArg) in structTy.typeVars.zip(typeArgs)) { + ctx.addConstraint(tyVar, tyArg) + } + ctx.processConstraints() + + ctx.resolveTy(structTy) } else -> TyUnknown } diff --git a/src/main/kotlin/org/move/lang/core/types/ty/TyStruct.kt b/src/main/kotlin/org/move/lang/core/types/ty/TyStruct.kt index cb75b8eac..71b2c7703 100644 --- a/src/main/kotlin/org/move/lang/core/types/ty/TyStruct.kt +++ b/src/main/kotlin/org/move/lang/core/types/ty/TyStruct.kt @@ -2,12 +2,9 @@ package org.move.lang.core.types.ty import org.move.ide.presentation.tyToString import org.move.lang.core.psi.MvStruct -import org.move.lang.core.psi.ext.declaredTy -import org.move.lang.core.psi.ext.fieldsMap import org.move.lang.core.psi.ext.tyAbilities import org.move.lang.core.types.infer.TypeFolder import org.move.lang.core.types.infer.TypeVisitor -import org.move.lang.core.types.infer.foldTyTypeParameterWith data class TyStruct( val item: MvStruct, @@ -28,16 +25,8 @@ data class TyStruct( override fun toString(): String = tyToString(this) - fun fieldsTy(): Map { - return this.item.fieldsMap.mapValues { (_, field) -> field.declaredTy(false) } - } - - fun fieldTy(name: String, msl: Boolean): Ty { - val field = this.item.fieldsMap[name] ?: return TyUnknown - return field.declaredTy(msl) - .foldTyTypeParameterWith { typeParam -> - this.typeVars.find { it.origin?.parameter == typeParam.parameter }!! - } + fun fieldTy(name: String): Ty { + return this.fieldTys[name] ?: TyUnknown } override fun innerVisitWith(visitor: TypeVisitor): Boolean { diff --git a/src/test/kotlin/org/move/ide/inspections/FieldInitShorthandInspectionTest.kt b/src/test/kotlin/org/move/ide/inspections/FieldInitShorthandInspectionTest.kt index ae78516c8..412cd1f24 100644 --- a/src/test/kotlin/org/move/ide/inspections/FieldInitShorthandInspectionTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/FieldInitShorthandInspectionTest.kt @@ -33,13 +33,17 @@ class FieldInitShorthandInspectionTest : InspectionTestBase(FieldInitShorthandIn fun `test fix for struct pattern`() = checkFixByText( "Use pattern shorthand", """ module 0x1::M { + struct S { foo: u8 } fun m() { + let foo = 1; let S { foo: foo/*caret*/ } = call(); } } """, """ module 0x1::M { + struct S { foo: u8 } fun m() { + let foo = 1; let S { foo } = call(); } } diff --git a/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt b/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt index 0eaa972bb..135d22bcf 100644 --- a/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt @@ -549,13 +549,13 @@ module 0x1::M { fun `test invalid type for field in struct literal`() = checkErrors( """ - module 0x1::M { - struct Deal { val: u8 } - fun main() { - Deal { val: false }; - } - } - """ +module 0x1::M { + struct Deal { val: u8 } + fun main() { + Deal { val: false }; + } +} +""" ) fun `test valid type for field`() = checkErrors( @@ -607,7 +607,7 @@ module 0x1::M { struct S { a: u8 } fun m() { let a = true; - S { a }; + S { a }; } } """ @@ -922,14 +922,17 @@ module 0x1::M { S</*caret*/Cat> {}; } } - """) + """ + ) - fun `test no error unpacking a struct from move_from`() = checkByText(""" + fun `test no error unpacking a struct from move_from`() = checkByText( + """ module 0x1::main { struct Container has key { val: u8 } fun main() { let Container { val } = move_from(source_addr); } } - """) + """ + ) } diff --git a/src/test/kotlin/org/move/lang/completion/KeywordCompletionTest.kt b/src/test/kotlin/org/move/lang/completion/KeywordCompletionTest.kt index 880df41c8..0ac3b19dc 100644 --- a/src/test/kotlin/org/move/lang/completion/KeywordCompletionTest.kt +++ b/src/test/kotlin/org/move/lang/completion/KeywordCompletionTest.kt @@ -578,4 +578,20 @@ class KeywordCompletionTest : CompletionTestCase() { } } """) + + fun `test bool completion in field initializer`() = doSingleCompletion(""" +module 0x1::main { + struct Container { val: Type } + fun main() { + Container { val: fa/*caret*/ }; + } +} + """, """ +module 0x1::main { + struct Container { val: Type } + fun main() { + Container { val: false/*caret*/ }; + } +} + """) } diff --git a/src/test/kotlin/org/move/lang/types/ExpectedTypeTest.kt b/src/test/kotlin/org/move/lang/types/ExpectedTypeTest.kt index 8baf8abef..f5fc653fe 100644 --- a/src/test/kotlin/org/move/lang/types/ExpectedTypeTest.kt +++ b/src/test/kotlin/org/move/lang/types/ExpectedTypeTest.kt @@ -90,6 +90,30 @@ class ExpectedTypeTest : TypificationTestCase() { """ ) + fun `test let statement struct pattern field explicit type`() = testExpectedTyExpr( + """ + module 0x1::Main { + struct S { val: Type } + fun main() { + let val: S = S { val: my_ref }; + //^ u8 + } + } + """ + ) + + fun `test let statement struct pattern field path type`() = testExpectedTyExpr( + """ + module 0x1::Main { + struct S { val: Type } + fun main() { + let S { val } = S { val: my_ref }; + //^ u8 + } + } + """ + ) + fun `test struct field literal`() = testExpectedTyExpr( """ module 0x1::Main { @@ -102,6 +126,31 @@ class ExpectedTypeTest : TypificationTestCase() { """ ) + fun `test struct field literal with generic`() = testExpectedTyExpr( + """ + module 0x1::Main { + struct S { val1: Type } + fun main() { + S { val1: my_ref }; + //^ u8 + } + } + """ + ) + + fun `test struct field literal with generic inferred from outer context`() = testExpectedTyExpr( + """ + module 0x1::Main { + struct S { val1: Type, val2: Type } + fun main() { + let a = 1u8; + S { val1: a, val2: my_ref }; + //^ u8 + } + } + """ + ) + fun `test null if inside other expr`() = testExpectedTyExpr( """ module 0x1::Main { diff --git a/src/test/kotlin/org/move/lang/types/ExpressionTypeInferenceTest.kt b/src/test/kotlin/org/move/lang/types/ExpressionTypeInferenceTest.kt index 6ad3902c3..58755728c 100644 --- a/src/test/kotlin/org/move/lang/types/ExpressionTypeInferenceTest.kt +++ b/src/test/kotlin/org/move/lang/types/ExpressionTypeInferenceTest.kt @@ -276,4 +276,37 @@ module 0x1::main { } } """) + + fun `tests struct unpacking incompatible field type`() = testExpr(""" +module 0x1::main { + struct Container { val: Type } + fun main() { + let Container { val } = Container { val: false }; + val; + //^ u8 + } +} + """) + + fun `test struct unpacking compatible field type inference`() = testExpr(""" +module 0x1::main { + struct Container { val: Type } + fun main() { + let Container { val } = Container { val: false }; + val; + //^ bool + } +} + """) + + fun `test struct unpacking with explicit type`() = testExpr(""" +module 0x1::main { + struct Container { val: Type } + fun main() { + let Container { val }: Container = call(); + val; + //^ u8 + } +} + """) } From 5d163f07549ebea5f6496af42e3e6a6daac92b2a Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Sat, 17 Sep 2022 13:47:52 +0200 Subject: [PATCH 10/26] refactor PhantomType inspection --- .../move/ide/docs/MvDocumentationProvider.kt | 2 +- .../hints/StructLiteralFieldsInfoHandler.kt | 2 +- .../type/MvTypeHintsPresentationFactory.kt | 2 +- .../ide/inspections/MvLocalInspectionTool.kt | 16 +++ .../ide/inspections/MvTypeCheckInspection.kt | 2 +- .../PhantomTypeParameterInspection.kt | 106 ++++++------------ .../move/ide/inspections/fixes/PhantomFix.kt | 43 +++++++ .../org/move/lang/core/psi/MvFunctionLike.kt | 4 +- .../lang/core/psi/ext/MoveStructFieldDef.kt | 2 +- .../org/move/lang/core/psi/ext/MvSchema.kt | 2 +- .../lang/core/types/infer/ExpectedType.kt | 3 - .../org/move/lang/core/types/infer/Fold.kt | 7 ++ .../lang/core/types/infer/InferenceContext.kt | 14 +-- .../lang/core/types/ty/TyTypeParameter.kt | 6 +- 14 files changed, 121 insertions(+), 90 deletions(-) create mode 100644 src/main/kotlin/org/move/ide/inspections/fixes/PhantomFix.kt diff --git a/src/main/kotlin/org/move/ide/docs/MvDocumentationProvider.kt b/src/main/kotlin/org/move/ide/docs/MvDocumentationProvider.kt index 5ab5e8b22..c0b058be9 100644 --- a/src/main/kotlin/org/move/ide/docs/MvDocumentationProvider.kt +++ b/src/main/kotlin/org/move/ide/docs/MvDocumentationProvider.kt @@ -128,7 +128,7 @@ fun MvElement.signature(builder: StringBuilder) { buffer += this.struct.name ?: angleWrapped("anonymous") buffer += "\n" buffer.b { it += this.name } - buffer += ": ${this.declaredTy(false).renderForDocs(true)}" + buffer += ": ${this.declarationTy(false).renderForDocs(true)}" } is MvConst -> { diff --git a/src/main/kotlin/org/move/ide/hints/StructLiteralFieldsInfoHandler.kt b/src/main/kotlin/org/move/ide/hints/StructLiteralFieldsInfoHandler.kt index 92b5ffcb6..ed62243ff 100644 --- a/src/main/kotlin/org/move/ide/hints/StructLiteralFieldsInfoHandler.kt +++ b/src/main/kotlin/org/move/ide/hints/StructLiteralFieldsInfoHandler.kt @@ -100,7 +100,7 @@ class FieldsDescription(val fields: Array) { val struct = block.litExpr.path.maybeStruct ?: return null val fieldParams = struct.fieldsMap.entries.map { (name, field) -> - val type = field.declaredTy(false).fullname() + val type = field.declarationTy(false).fullname() "$name: $type" }.toTypedArray() return FieldsDescription(fieldParams) diff --git a/src/main/kotlin/org/move/ide/hints/type/MvTypeHintsPresentationFactory.kt b/src/main/kotlin/org/move/ide/hints/type/MvTypeHintsPresentationFactory.kt index 7e690195b..3639c880a 100644 --- a/src/main/kotlin/org/move/ide/hints/type/MvTypeHintsPresentationFactory.kt +++ b/src/main/kotlin/org/move/ide/hints/type/MvTypeHintsPresentationFactory.kt @@ -34,7 +34,7 @@ class MvTypeHintsPresentationFactory(private val factory: PresentationFactory) { ).join() private fun typeParameterTypeHint(type: TyTypeParameter): InlayPresentation { - return text(type.parameter.name) + return text(type.origin.name) } private fun parametersHint(kinds: List, level: Int): InlayPresentation = diff --git a/src/main/kotlin/org/move/ide/inspections/MvLocalInspectionTool.kt b/src/main/kotlin/org/move/ide/inspections/MvLocalInspectionTool.kt index 3f2bf89e0..df86af561 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvLocalInspectionTool.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvLocalInspectionTool.kt @@ -5,8 +5,10 @@ import com.intellij.codeInspection.LocalInspectionToolSession import com.intellij.codeInspection.LocalQuickFix import com.intellij.codeInspection.LocalQuickFixOnPsiElement import com.intellij.codeInspection.ProblemsHolder +import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement import com.intellij.psi.PsiElementVisitor +import com.intellij.psi.PsiFile import org.move.cli.moveProjects import org.move.lang.MoveFile import org.move.lang.core.psi.MvVisitor @@ -51,3 +53,17 @@ abstract class MvLocalInspectionTool : LocalInspectionTool() { abstract class InspectionQuickFix(val fixName: String) : LocalQuickFix { override fun getFamilyName(): String = fixName } + +abstract class MvLocalQuickFixOnPsiElement(psiElement: T): LocalQuickFixOnPsiElement(psiElement) { + override fun invoke(project: Project, file: PsiFile, startElement: PsiElement, endElement: PsiElement) { + @Suppress("UNCHECKED_CAST") + val element = startElement as T + if (stillApplicable(project, file, element)) { + invoke(project, file, element) + } + } + + abstract fun stillApplicable(project: Project, file: PsiFile, element: T): Boolean + + abstract fun invoke(project: Project, file: PsiFile, element: T) +} diff --git a/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt b/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt index 800fb404b..c8ebea9c8 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt @@ -94,7 +94,7 @@ class MvTypeCheckInspection : MvLocalInspectionTool() { val structAbilities = field.struct.tyAbilities if (structAbilities.isEmpty()) return - val fieldTy = field.declaredTy(msl) as? TyStruct ?: return + val fieldTy = field.declarationTy(msl) as? TyStruct ?: return for (ability in structAbilities) { val requiredAbility = ability.requires() if (requiredAbility !in fieldTy.abilities()) { diff --git a/src/main/kotlin/org/move/ide/inspections/PhantomTypeParameterInspection.kt b/src/main/kotlin/org/move/ide/inspections/PhantomTypeParameterInspection.kt index 8ed00169f..058401748 100644 --- a/src/main/kotlin/org/move/ide/inspections/PhantomTypeParameterInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/PhantomTypeParameterInspection.kt @@ -1,96 +1,64 @@ package org.move.ide.inspections -import com.intellij.codeInspection.LocalQuickFix -import com.intellij.codeInspection.ProblemDescriptor import com.intellij.codeInspection.ProblemsHolder -import com.intellij.openapi.project.Project import com.intellij.psi.util.descendantsOfType +import org.move.ide.inspections.fixes.PhantomFix import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.* -import org.move.lang.core.types.infer.foldTyTypeParameterWith +import org.move.lang.core.types.infer.visitTyTypeParameterWith class PhantomTypeParameterInspection : MvLocalInspectionTool() { override fun buildMvVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): MvVisitor { return object : MvVisitor() { - override fun visitTypeParameterList(o: MvTypeParameterList) { - val struct = o.ancestorStrict(stopAt = MvCodeBlock::class.java) ?: return - val fields = struct.fields - val usedParamNames = mutableListOf() - for (field in fields) { - val paramNames = mutableListOf() - field.declaredTy(false).foldTyTypeParameterWith { param -> - val typeParameter = param.parameter - val name = typeParameter.name - if (name != null) { - paramNames.add(name) - } - param - } - run { - val fieldType = field.typeAnnotation?.type ?: return@run - val typeLists = fieldType.descendantsOfType() - for (typeList in typeLists) { - val path = typeList.parent as MvPath + override fun visitStruct(o: MvStruct) { + val usedTypeParams = mutableSetOf() + + for (structField in o.fields) { + val fieldUsedTypeParams = mutableListOf() + + // find all MvTypeParameter used in field declaration + structField.declarationTy(false) + .visitTyTypeParameterWith { fieldUsedTypeParams.add(it.origin) } + + // find all MvTypeArgument, check their phantom status + val fieldType = structField.typeAnnotation?.type + if (fieldType != null) { + val paths = fieldType.descendantsOfType() + for (path in paths) { + // stop if empty + if (path.typeArguments.isEmpty()) continue + // determine phantom status of every argument, drop if phantom val outerStruct = path.reference?.resolve() as? MvStruct ?: continue - for ((i, typeArg) in typeList.typeArgumentList.withIndex()) { - val typeParam = typeArg.type - .moveReference?.resolve() as? MvTypeParameter ?: continue + for ((i, typeArg) in path.typeArguments.withIndex()) { val outerTypeParam = outerStruct.typeParameters.getOrNull(i) ?: continue if (outerTypeParam.isPhantom) { - paramNames.remove(typeParam.name) + val typeParam = + typeArg.type.moveReference?.resolve() as? MvTypeParameter ?: continue + fieldUsedTypeParams.remove(typeParam) } } } } - usedParamNames.addAll(paramNames) + usedTypeParams.addAll(fieldUsedTypeParams) } - for (typeParam in o.typeParameterList) { - val typeParamName = typeParam.name ?: continue - if (typeParam.isPhantom) { - if (typeParamName !in usedParamNames) { - continue - } else { + + for (typeParam in o.typeParameters) { + when { + typeParam.isPhantom && typeParam in usedTypeParams -> { holder.registerProblem( typeParam, "Cannot be phantom", - object : LocalQuickFix { - override fun getFamilyName(): String { - return "Remove phantom" - } - - override fun applyFix(project: Project, descriptor: ProblemDescriptor) { - var paramText = typeParamName - val tp = descriptor.psiElement as? MvTypeParameter ?: return - if (tp.abilities.isNotEmpty()) { - paramText += - ": " + tp.abilities.joinToString(", ") { it.text } - } - val newParam = project.psiFactory.typeParameter(paramText) - tp.replace(newParam) - } - } + PhantomFix.Remove(typeParam) ) } - } - if (typeParamName !in usedParamNames) { - holder.registerProblem( - typeParam, - "Unused type parameter. Consider declaring it as phantom", - object : LocalQuickFix { - override fun getFamilyName() = "Declare phantom" + !typeParam.isPhantom && typeParam !in usedTypeParams -> { + holder.registerProblem( + typeParam, + "Unused type parameter. Consider declaring it as phantom", + PhantomFix.Add(typeParam) + ) - override fun applyFix(project: Project, descriptor: ProblemDescriptor) { - var paramText = "phantom $typeParamName" - val tp = descriptor.psiElement as? MvTypeParameter ?: return - if (tp.abilities.isNotEmpty()) { - paramText += - ": " + tp.abilities.joinToString(", ") { it.text } - } - val newParam = project.psiFactory.typeParameter(paramText) - tp.replace(newParam) - } - } - ) + } } } } diff --git a/src/main/kotlin/org/move/ide/inspections/fixes/PhantomFix.kt b/src/main/kotlin/org/move/ide/inspections/fixes/PhantomFix.kt new file mode 100644 index 000000000..52341e4a9 --- /dev/null +++ b/src/main/kotlin/org/move/ide/inspections/fixes/PhantomFix.kt @@ -0,0 +1,43 @@ +package org.move.ide.inspections.fixes + +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiFile +import org.move.ide.inspections.MvLocalQuickFixOnPsiElement +import org.move.lang.core.psi.MvTypeParameter +import org.move.lang.core.psi.ext.isPhantom +import org.move.lang.core.psi.psiFactory + +sealed class PhantomFix(typeParam: MvTypeParameter): MvLocalQuickFixOnPsiElement(typeParam) { + + class Add(typeParameter: MvTypeParameter): PhantomFix(typeParameter) { + + override fun getFamilyName(): String = "Declare phantom" + override fun getText(): String = "Declare phantom" + + override fun stillApplicable(project: Project, file: PsiFile, element: MvTypeParameter): Boolean = + !element.isPhantom + + override fun invoke(project: Project, file: PsiFile, element: MvTypeParameter) { + val newText = "phantom ${element.text}" + val newTypeParameter = project.psiFactory.typeParameter(newText) + element.replace(newTypeParameter) + } + } + + class Remove(typeParameter: MvTypeParameter): PhantomFix(typeParameter) { + + override fun getFamilyName(): String = "Remove phantom" + override fun getText(): String = "Remove phantom" + + override fun stillApplicable(project: Project, file: PsiFile, element: MvTypeParameter): Boolean = + element.isPhantom + + override fun invoke(project: Project, file: PsiFile, element: MvTypeParameter) { + val boundText = element.typeParamBound?.text ?: "" + val newText = "${element.name}$boundText" + val newTypeParameter = project.psiFactory.typeParameter(newText) + element.replace(newTypeParameter) + } + } + +} diff --git a/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt b/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt index 890975cc4..d089a3efe 100644 --- a/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt +++ b/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt @@ -43,7 +43,7 @@ val MvFunctionLike.typeParamsUsedOnlyInReturnType: List this.parameters .map { it.declaredTy(false) } .forEach { - it.foldTyTypeParameterWith { paramTy -> usedTypeParams.add(paramTy.parameter); paramTy } + it.foldTyTypeParameterWith { paramTy -> usedTypeParams.add(paramTy.origin); paramTy } } return this.typeParameters.filter { it !in usedTypeParams } } @@ -55,7 +55,7 @@ val MvFunctionLike.requiredTypeParams: List .map { it.declaredTy(false) } .chain(this.returnType?.type?.ty().wrapWithList()) .forEach { - it.foldTyTypeParameterWith { paramTy -> usedTypeParams.add(paramTy.parameter); paramTy } + it.foldTyTypeParameterWith { paramTy -> usedTypeParams.add(paramTy.origin); paramTy } } return this.typeParameters.filter { it !in usedTypeParams } } diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MoveStructFieldDef.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MoveStructFieldDef.kt index 0126663c7..c4d601c0c 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MoveStructFieldDef.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MoveStructFieldDef.kt @@ -15,5 +15,5 @@ val MvStructField.struct: MvStruct get() = fieldsDefBlock?.parent as MvStruct -fun MvStructField.declaredTy(msl: Boolean): Ty = +fun MvStructField.declarationTy(msl: Boolean): Ty = this.typeAnnotation?.type?.let { inferTypeTy(it, msl) } ?: TyUnknown diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvSchema.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvSchema.kt index b0369c3f3..fdb843a61 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvSchema.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvSchema.kt @@ -19,7 +19,7 @@ val MvSchema.requiredTypeParams: List this.fieldStmts .map { it.declaredTy(true) } .forEach { - it.foldTyTypeParameterWith { paramTy -> usedTypeParams.add(paramTy.parameter); paramTy } + it.foldTyTypeParameterWith { paramTy -> usedTypeParams.add(paramTy.origin); paramTy } } return this.typeParameters.filter { it !in usedTypeParams } } diff --git a/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt b/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt index e94463e85..c60651b7f 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt @@ -2,14 +2,11 @@ package org.move.lang.core.types.infer import com.intellij.psi.PsiElement import org.move.lang.core.psi.* -import org.move.lang.core.psi.ext.declaredTy import org.move.lang.core.psi.ext.isMsl import org.move.lang.core.psi.ext.structLitExpr -import org.move.lang.core.psi.ext.ty import org.move.lang.core.types.ty.Ty import org.move.lang.core.types.ty.TyReference import org.move.lang.core.types.ty.TyStruct -import org.move.lang.core.types.ty.TyUnknown fun inferExpectedTy(element: PsiElement, ctx: InferenceContext): Ty? { val owner = element.parent diff --git a/src/main/kotlin/org/move/lang/core/types/infer/Fold.kt b/src/main/kotlin/org/move/lang/core/types/infer/Fold.kt index 6c53c46d9..01843d56c 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/Fold.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/Fold.kt @@ -72,6 +72,13 @@ fun TypeFoldable.foldTyTypeParameterWith(folder: (TyTypeParameter) -> Ty) if (ty is TyTypeParameter) folder(ty) else ty.innerFoldWith(this) }) // + +fun TypeFoldable.visitTyTypeParameterWith(visitor: (TyTypeParameter) -> Boolean) = + visitWith(object : TypeVisitor { + override fun invoke(ty: Ty): Boolean = + if (ty is TyTypeParameter) visitor(ty) else ty.innerVisitWith(this) + }) +// ///** Deeply replace any [TyInfer] with the function [folder] */ //fun TypeFoldable.foldTyInfersWith(folder: (TyInfer) -> Ty): T = // foldWith(object : TypeFolder { diff --git a/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt b/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt index 03d73bb87..195b4df35 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt @@ -89,7 +89,7 @@ fun instantiateItemTy(item: MvNameIdentifierOwner, msl: Boolean): Ty { is MvStruct -> { val typeVars = item.typeParameters.map { TyInfer.TyVar(TyTypeParameter(it)) } fun findTypeVar(parameter: MvTypeParameter): Ty { - return typeVars.find { it.origin?.parameter == parameter }!! + return typeVars.find { it.origin?.origin == parameter }!! } val fieldTys = mutableMapOf() @@ -97,8 +97,8 @@ fun instantiateItemTy(item: MvNameIdentifierOwner, msl: Boolean): Ty { val fieldName = field.name ?: return TyUnknown val fieldTy = item .fieldsMap[fieldName] - ?.declaredTy(msl) - ?.foldTyTypeParameterWith { findTypeVar(it.parameter) } + ?.declarationTy(msl) + ?.foldTyTypeParameterWith { findTypeVar(it.origin) } ?: TyUnknown fieldTys[fieldName] = fieldTy } @@ -110,27 +110,27 @@ fun instantiateItemTy(item: MvNameIdentifierOwner, msl: Boolean): Ty { is MvFunctionLike -> { val typeVars = item.typeParameters.map { TyInfer.TyVar(TyTypeParameter(it)) } fun findTypeVar(parameter: MvTypeParameter): Ty { - return typeVars.find { it.origin?.parameter == parameter }!! + return typeVars.find { it.origin?.origin == parameter }!! } val paramTypes = mutableListOf() for (param in item.parameters) { val paramType = param.typeAnnotation?.type ?.let { inferTypeTy(it, msl) } - ?.foldTyTypeParameterWith { findTypeVar(it.parameter) } ?: TyUnknown + ?.foldTyTypeParameterWith { findTypeVar(it.origin) } ?: TyUnknown paramTypes.add(paramType) } val returnMvType = item.returnType?.type val retTy = if (returnMvType == null) { TyUnit } else { - inferTypeTy(returnMvType, msl).foldTyTypeParameterWith { findTypeVar(it.parameter) } + inferTypeTy(returnMvType, msl).foldTyTypeParameterWith { findTypeVar(it.origin) } } val acqTys = item.acquiresPathTypes.map { val acqItem = it.path.reference?.resolve() as? MvNameIdentifierOwner ?: return@map TyUnknown instantiateItemTy(acqItem, msl) - .foldTyTypeParameterWith { tp -> findTypeVar(tp.parameter) } + .foldTyTypeParameterWith { tp -> findTypeVar(tp.origin) } } val typeArgs = item.typeParameters.map { findTypeVar(it) } TyFunction(item, typeVars, paramTypes, retTy, acqTys, typeArgs) diff --git a/src/main/kotlin/org/move/lang/core/types/ty/TyTypeParameter.kt b/src/main/kotlin/org/move/lang/core/types/ty/TyTypeParameter.kt index ca21bbd7a..d0458888c 100644 --- a/src/main/kotlin/org/move/lang/core/types/ty/TyTypeParameter.kt +++ b/src/main/kotlin/org/move/lang/core/types/ty/TyTypeParameter.kt @@ -6,12 +6,12 @@ import org.move.lang.core.psi.ext.abilities import org.move.lang.core.psi.ext.ability -data class TyTypeParameter(val parameter: MvTypeParameter) : Ty { +data class TyTypeParameter(val origin: MvTypeParameter) : Ty { - val name: String? get() = parameter.name + val name: String? get() = origin.name override fun abilities(): Set { - return parameter.abilities.mapNotNull { it.ability }.toSet() + return origin.abilities.mapNotNull { it.ability }.toSet() } override fun toString(): String = tyToString(this) From 13bb537449125a6bae07889491381442bda7787c Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Sat, 17 Sep 2022 14:32:02 +0200 Subject: [PATCH 11/26] unsuccessful attempt to make add ability quickfix --- src/main/kotlin/org/move/cli/MoveProject.kt | 2 +- .../ide/inspections/MvTypeCheckInspection.kt | 2 +- .../org/move/lang/core/psi/MvFunctionLike.kt | 2 +- .../org/move/lang/core/psi/ext/MvStruct.kt | 19 +++++++++ .../org/move/lang/core/psi/ext/MvUseStmt.kt | 1 + .../org/move/lang/core/psi/ext/PsiElement.kt | 3 -- .../move/lang/core/resolve/NameResolution.kt | 1 + .../resolve/ref/MoveFQModuleReferenceImpl.kt | 2 +- .../resolve/ref/MoveModuleReferenceImpl.kt | 2 +- .../lang/core/types/infer/InferenceContext.kt | 39 +------------------ .../kotlin/org/move/stdext/Collections.kt | 5 +++ .../inspections/MvTypeCheckInspectionTest.kt | 37 ------------------ 12 files changed, 33 insertions(+), 82 deletions(-) diff --git a/src/main/kotlin/org/move/cli/MoveProject.kt b/src/main/kotlin/org/move/cli/MoveProject.kt index b0c5a457e..81a5e652f 100644 --- a/src/main/kotlin/org/move/cli/MoveProject.kt +++ b/src/main/kotlin/org/move/cli/MoveProject.kt @@ -11,7 +11,6 @@ import com.intellij.psi.util.PsiModificationTracker import com.intellij.util.containers.addIfNotNull import org.move.cli.manifest.MoveToml import org.move.lang.MoveFile -import org.move.lang.core.psi.ext.wrapWithList import org.move.lang.core.types.Address import org.move.lang.toMoveFile import org.move.lang.toNioPathOrNull @@ -19,6 +18,7 @@ import org.move.openapiext.common.checkUnitTestMode import org.move.openapiext.contentRoots import org.move.stdext.chain import org.move.stdext.iterateMoveVirtualFiles +import org.move.stdext.wrapWithList import java.nio.file.Path data class MoveProject( diff --git a/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt b/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt index c8ebea9c8..0a9ccbcdf 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt @@ -1,5 +1,6 @@ package org.move.ide.inspections +import com.intellij.codeInspection.LocalQuickFix import com.intellij.codeInspection.ProblemHighlightType import com.intellij.codeInspection.ProblemsHolder import com.intellij.codeInspection.util.InspectionMessage @@ -26,7 +27,6 @@ fun ProblemsHolder.registerTypeError(typeError: TypeError) { typeError.element, typeError.message(), ProblemHighlightType.GENERIC_ERROR, - typeError.quickfix() ) } diff --git a/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt b/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt index d089a3efe..243466c2f 100644 --- a/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt +++ b/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt @@ -4,13 +4,13 @@ import org.move.lang.MvElementTypes import org.move.lang.core.psi.ext.MvDocAndAttributeOwner import org.move.lang.core.psi.ext.hasChild import org.move.lang.core.psi.ext.ty -import org.move.lang.core.psi.ext.wrapWithList import org.move.lang.core.psi.mixins.declaredTy import org.move.lang.core.types.infer.foldTyTypeParameterWith import org.move.lang.core.types.ty.Ty import org.move.lang.core.types.ty.TyUnit import org.move.lang.core.types.ty.TyUnknown import org.move.stdext.chain +import org.move.stdext.wrapWithList interface MvFunctionLike : MvTypeParametersOwner, MvNameIdentifierOwner, diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvStruct.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvStruct.kt index 9b3724c78..7cc1e7cbc 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvStruct.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvStruct.kt @@ -3,9 +3,11 @@ package org.move.lang.core.psi.ext import com.intellij.lang.ASTNode import com.intellij.psi.util.descendantsOfType import org.move.ide.MoveIcons +import org.move.lang.MvElementTypes import org.move.lang.core.psi.* import org.move.lang.core.psi.impl.MvNameIdentifierOwnerImpl import org.move.lang.core.types.ty.Ability +import org.move.stdext.withElement import javax.swing.Icon val MvStruct.fields: List @@ -45,6 +47,23 @@ val MvStruct.tyAbilities: Set get() = this.abilities.mapNotNull { it.ab val MvStruct.hasPhantomTypeParameters get() = this.typeParameters.any { it.isPhantom } +fun MvStruct.addAbility(ability: String) { + if (ability in this.abilities.map { it.text }) return + + val newAbilities = this.abilities.mapNotNull { it.text }.withElement(ability) + val newAbilitiesList = project.psiFactory.abilitiesList(newAbilities) + if (this.abilitiesList != null) { + this.abilitiesList?.replace(newAbilitiesList) + } else { + val anchor = when { + this.structBlock != null -> this.structBlock + this.hasChild(MvElementTypes.SEMICOLON) -> this.getChild(MvElementTypes.SEMICOLON) + else -> return + } + this.addBefore(newAbilitiesList, anchor) + } +} + abstract class MvStructMixin(node: ASTNode) : MvNameIdentifierOwnerImpl(node), MvStruct { diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvUseStmt.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvUseStmt.kt index 4fdb2c45e..6384b1ee0 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvUseStmt.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvUseStmt.kt @@ -4,6 +4,7 @@ import org.move.lang.core.psi.MvAddressRef import org.move.lang.core.psi.MvFQModuleRef import org.move.lang.core.psi.MvUseItem import org.move.lang.core.psi.MvUseStmt +import org.move.stdext.wrapWithList val MvUseStmt.addressRef: MvAddressRef? get() { diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/PsiElement.kt b/src/main/kotlin/org/move/lang/core/psi/ext/PsiElement.kt index 59414e064..9b326a3f9 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/PsiElement.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/PsiElement.kt @@ -10,9 +10,6 @@ import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.util.PsiUtilCore import org.move.lang.core.psi.* -fun T?.wrapWithList(): List = this?.let { listOf(it) }.orEmpty() -fun T?.wrapWithMutableList(): MutableList = this?.let { listOf(it) }.orEmpty().toMutableList() - fun PsiElement.hasChild(tokenType: IElementType): Boolean = childrenByType(tokenType).toList().isNotEmpty() fun PsiElement.getChild(tokenType: IElementType): PsiElement? = childrenByType(tokenType).firstOrNull() diff --git a/src/main/kotlin/org/move/lang/core/resolve/NameResolution.kt b/src/main/kotlin/org/move/lang/core/resolve/NameResolution.kt index 55db3cb54..756c18a2d 100644 --- a/src/main/kotlin/org/move/lang/core/resolve/NameResolution.kt +++ b/src/main/kotlin/org/move/lang/core/resolve/NameResolution.kt @@ -15,6 +15,7 @@ import org.move.lang.modules import org.move.lang.moveProject import org.move.lang.toNioPathOrNull import org.move.stdext.chain +import org.move.stdext.wrapWithList enum class MslScope { NONE, EXPR, LET, LET_POST; diff --git a/src/main/kotlin/org/move/lang/core/resolve/ref/MoveFQModuleReferenceImpl.kt b/src/main/kotlin/org/move/lang/core/resolve/ref/MoveFQModuleReferenceImpl.kt index e68334803..713403bc9 100644 --- a/src/main/kotlin/org/move/lang/core/resolve/ref/MoveFQModuleReferenceImpl.kt +++ b/src/main/kotlin/org/move/lang/core/resolve/ref/MoveFQModuleReferenceImpl.kt @@ -3,8 +3,8 @@ package org.move.lang.core.resolve.ref import org.move.lang.core.psi.MvFQModuleRef import org.move.lang.core.psi.MvModule import org.move.lang.core.psi.MvNamedElement -import org.move.lang.core.psi.ext.wrapWithList import org.move.lang.core.resolve.processFQModuleRef +import org.move.stdext.wrapWithList interface MvFQModuleReference : MvReference { override fun resolve(): MvNamedElement? diff --git a/src/main/kotlin/org/move/lang/core/resolve/ref/MoveModuleReferenceImpl.kt b/src/main/kotlin/org/move/lang/core/resolve/ref/MoveModuleReferenceImpl.kt index 5038b1ac5..bb87888de 100644 --- a/src/main/kotlin/org/move/lang/core/resolve/ref/MoveModuleReferenceImpl.kt +++ b/src/main/kotlin/org/move/lang/core/resolve/ref/MoveModuleReferenceImpl.kt @@ -3,8 +3,8 @@ package org.move.lang.core.resolve.ref import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.isSelf import org.move.lang.core.psi.ext.moduleImport -import org.move.lang.core.psi.ext.wrapWithList import org.move.lang.core.resolve.resolveSingleItem +import org.move.stdext.wrapWithList class MvModuleReferenceImpl( element: MvModuleRef, diff --git a/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt b/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt index 195b4df35..3c0ebcbe0 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt @@ -1,25 +1,18 @@ package org.move.lang.core.types.infer -import com.intellij.codeInspection.LocalQuickFix -import com.intellij.codeInspection.ProblemDescriptor -import com.intellij.openapi.project.Project import com.intellij.openapi.util.Key import com.intellij.psi.PsiElement import com.intellij.psi.util.CachedValue import com.intellij.psi.util.CachedValuesManager.getProjectPsiDependentCache import com.jetbrains.rd.util.concurrentMapOf -import org.move.ide.inspections.InspectionQuickFix import org.move.ide.presentation.expectedBindingFormText import org.move.ide.presentation.name import org.move.ide.presentation.text -import org.move.lang.MvElementTypes.SEMICOLON import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.* import org.move.lang.core.psi.mixins.ty import org.move.lang.core.types.ty.* -private val TYPE_INFERENCE_KEY: Key> = Key.create("TYPE_INFERENCE_KEY") - fun MvElement.functionInferenceCtx(msl: Boolean = this.isMsl()): InferenceContext { return this.containingFunctionLike?.inferenceCtx(msl) ?: InferenceContext(msl) } @@ -241,7 +234,6 @@ fun isCompatibleAbilities(expectedTy: Ty, actualTy: Ty, msl: Boolean): Compat { sealed class TypeError(open val element: PsiElement) { abstract fun message(): String - open fun quickfix(): LocalQuickFix? = null data class TypeMismatch( override val element: PsiElement, @@ -259,38 +251,11 @@ sealed class TypeError(open val element: PsiElement) { data class AbilitiesMismatch( override val element: PsiElement, val ty: Ty, - val abilities: Set + val missingAbilities: Set ) : TypeError(element) { override fun message(): String { return "The type '${ty.text()}' " + - "does not have required ability '${abilities.map { it.label() }.first()}'" - } - - override fun quickfix(): LocalQuickFix? { - if (abilities.size > 1) return null - val abilityName = abilities.map { it.label() }.first() - return object : InspectionQuickFix("Add '$abilityName' ability to ${ty.name()}") { - override fun applyFix(project: Project, descriptor: ProblemDescriptor) { - val pathType = descriptor.psiElement as? MvPathType ?: return - val struct = pathType.reference?.resolve() as? MvStruct ?: return - // sanity check - val existingAbilities = struct.abilities.map { it.text } - if (abilityName in existingAbilities) return - - val newList = project.psiFactory.abilitiesList(existingAbilities + listOf(abilityName)) - if (struct.abilitiesList != null) { - struct.abilitiesList?.replace(newList) - } else { - val anchor = when { - struct.structBlock != null -> struct.structBlock - struct.hasChild(SEMICOLON) -> struct.getChild(SEMICOLON) - else -> return - } - struct.addBefore(newList, anchor) - } - struct.abilitiesList?.replace(newList) - } - } + "does not have required ability '${missingAbilities.map { it.label() }.first()}'" } } diff --git a/src/main/kotlin/org/move/stdext/Collections.kt b/src/main/kotlin/org/move/stdext/Collections.kt index b7c811a10..c8c64e5f2 100644 --- a/src/main/kotlin/org/move/stdext/Collections.kt +++ b/src/main/kotlin/org/move/stdext/Collections.kt @@ -188,3 +188,8 @@ private class LookbackIterator(private val iterator: Iterator) : Iterator< fun MutableMap>.putGrouped(key: K, value: V) { getOrPut(key) { mutableListOf() }.add(value) } + +fun T?.wrapWithList(): List = this?.let { listOf(it) }.orEmpty() +fun T?.wrapWithMutableList(): MutableList = this?.let { listOf(it) }.orEmpty().toMutableList() + +fun List.withElement(element: T): List = listOf(this, listOf(element)).flatten() diff --git a/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt b/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt index 135d22bcf..32c67d9ab 100644 --- a/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt @@ -888,43 +888,6 @@ module 0x1::M { """ ) - fun `test missing key ability with quickfix`() = checkFixByText( - "Add 'key' ability to Cat", - """ - module 0x1::main { - struct Cat has drop {} - struct S {} - fun main() { - S</*caret*/Cat> {}; - } - } - """, """ - module 0x1::main { - struct Cat has drop, key {} - struct S {} - fun main() { - S {}; - } - } - """ - ) - - fun `test no missing ability quickfix in other module struct`() = checkFixIsUnavailable( - "Add 'key' ability to Cat", - """ - module 0x1::pets { - struct Cat {} - } - module 0x1::main { - use 0x1::pets::Cat; - struct S {} - fun main() { - S</*caret*/Cat> {}; - } - } - """ - ) - fun `test no error unpacking a struct from move_from`() = checkByText( """ module 0x1::main { From 54960c9cb4e4c923ab83df1d3a3f43a98dda1de4 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Sat, 17 Sep 2022 15:51:19 +0200 Subject: [PATCH 12/26] add parser support for spec function signature redeclaration --- changelog/1.20.0.md | 4 +- src/main/grammars/MoveParser.bnf | 37 +++++++- .../psi/ext/MvItemSpecFunctionParameter.kt | 29 +++++++ .../core/psi/ext/MvItemSpecTypeParameter.kt | 27 ++++++ .../move/lang/core/resolve/NameResolution.kt | 2 - .../org/move/lang/resolve/ResolveTypesTest.kt | 11 +++ .../move/lang/resolve/ResolveVariablesTest.kt | 11 +++ .../move/lang/types/ExpressionTypesTest.kt | 42 +++++++++ .../org/move/lang/parser/partial/spec.txt | 6 +- .../org/move/lang/parser/specs/scopes.move | 5 ++ .../org/move/lang/parser/specs/scopes.txt | 85 +++++++++++++++++++ 11 files changed, 252 insertions(+), 7 deletions(-) create mode 100644 src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpecFunctionParameter.kt create mode 100644 src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpecTypeParameter.kt diff --git a/changelog/1.20.0.md b/changelog/1.20.0.md index b8727d407..91132b1ce 100644 --- a/changelog/1.20.0.md +++ b/changelog/1.20.0.md @@ -16,7 +16,9 @@ TODO: screenshot * Sort completions by abilities in type parameters. -* Support imports inside code blocks. +* Support for imports inside code blocks. + +* Allow repeating function signature in spec for readability. ## Fixes diff --git a/src/main/grammars/MoveParser.bnf b/src/main/grammars/MoveParser.bnf index a1430387d..dccf34327 100644 --- a/src/main/grammars/MoveParser.bnf +++ b/src/main/grammars/MoveParser.bnf @@ -1079,10 +1079,45 @@ private ModuleSpecBlock_item_recover ::= !('}' | <> | spec | use) //AnySpec ::= ItemSpec | ModuleKeywordSpec -ItemSpec ::= spec ItemSpecRef <> +ItemSpec ::= spec ItemSpecRef ItemSpecTypeParameterList? ItemSpecFunctionParameterList? ReturnType? + <> { pin = 1 } +ItemSpecTypeParameterList ::= '<' ItemSpecTypeParameter_with_recover* '>' +{ + pin = 1 +} +private ItemSpecTypeParameter_with_recover ::= !'>' ItemSpecTypeParameter (',' | &'>') +{ + pin = 1 + recoverWhile = ItemSpecTypeParameter_recover +} +private ItemSpecTypeParameter_recover ::= !('>' | '(' | '{' | phantom | IDENTIFIER) + +ItemSpecTypeParameter ::= IDENTIFIER { + pin = 2 +// implements = [ +// "org.move.lang.core.resolve.MvMandatoryReferenceElement" +// ] +// mixin = "org.move.lang.core.psi.ext.MvItemSpecTypeParameterMixin" +} + +ItemSpecFunctionParameterList ::= '(' ItemSpecFunctionParameter_with_recover* ')' { pin = 1 } +private ItemSpecFunctionParameter_with_recover ::= !(')' | '{' | ';') ItemSpecFunctionParameter (',' | &')') +{ + pin = 1 + recoverWhile = ItemSpecFunctionParameter_recover +} +private ItemSpecFunctionParameter_recover ::= !(')' | '{' | ';' | IDENTIFIER) + +ItemSpecFunctionParameter ::= IDENTIFIER TypeAnnotation { + pin = 1 +// implements = [ +// "org.move.lang.core.resolve.MvMandatoryReferenceElement" +// ] +// mixin = "org.move.lang.core.psi.ext.MvItemSpecFunctionParameterMixin" +} ItemSpecRef ::= MODULE_KW | IDENTIFIER { diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpecFunctionParameter.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpecFunctionParameter.kt new file mode 100644 index 000000000..6fbdf2688 --- /dev/null +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpecFunctionParameter.kt @@ -0,0 +1,29 @@ +package org.move.lang.core.psi.ext + +import com.intellij.lang.ASTNode +import org.move.lang.core.psi.MvElementImpl +import org.move.lang.core.psi.MvItemSpecFunctionParameter +import org.move.lang.core.psi.MvNamedElement +import org.move.lang.core.resolve.ref.MvReference +import org.move.lang.core.resolve.ref.MvReferenceCached +import org.move.lang.core.resolve.ref.Namespace +import org.move.lang.core.resolve.resolveSingleItem + +//class MvItemSpecFunctionParameterReferenceImpl( +// element: MvItemSpecFunctionParameter +//) : MvReferenceCached(element) { +// +// override fun resolveInner(): List { +// return listOfNotNull( +// resolveSingleItem(element, setOf(Namespace.FUNCTION_PARAM)) +// ) +// +// } +//} + +abstract class MvItemSpecFunctionParameterMixin(node: ASTNode) : MvElementImpl(node), + MvItemSpecFunctionParameter { +// override fun getReference(): MvReference { +// return MvItemSpecFunctionParameterReferenceImpl(this) +// } +} diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpecTypeParameter.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpecTypeParameter.kt new file mode 100644 index 000000000..1488b2dd3 --- /dev/null +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpecTypeParameter.kt @@ -0,0 +1,27 @@ +package org.move.lang.core.psi.ext + +import com.intellij.lang.ASTNode +import org.move.lang.core.psi.MvElementImpl +import org.move.lang.core.psi.MvItemSpecFunctionParameter +import org.move.lang.core.psi.MvItemSpecTypeParameter +import org.move.lang.core.psi.MvNamedElement +import org.move.lang.core.resolve.ref.MvReference +import org.move.lang.core.resolve.ref.MvReferenceCached +import org.move.lang.core.resolve.ref.Namespace +import org.move.lang.core.resolve.resolveSingleItem + +//class MvItemSpecTypeParameterReferenceImpl( +// element: MvItemSpecTypeParameter +//) : MvReferenceCached(element) { +// +// override fun resolveInner(): List { +// return emptyList() +// } +//} + +abstract class MvItemSpecTypeParameterMixin(node: ASTNode) : MvElementImpl(node), + MvItemSpecTypeParameter { +// override fun getReference(): MvReference { +// return MvItemSpecTypeParameterReferenceImpl(this) +// } +} diff --git a/src/main/kotlin/org/move/lang/core/resolve/NameResolution.kt b/src/main/kotlin/org/move/lang/core/resolve/NameResolution.kt index 756c18a2d..de9ab7f07 100644 --- a/src/main/kotlin/org/move/lang/core/resolve/NameResolution.kt +++ b/src/main/kotlin/org/move/lang/core/resolve/NameResolution.kt @@ -30,8 +30,6 @@ fun MvElement.isVisibleInScope(itemScope: ItemScope): Boolean { || this.itemScope == ItemScope.MAIN } -//fun MvElement.isVisibleInScopes(itemVis: ItemVis): Boolean = this.visibleInScope(itemVis.itemScope) - val MvElement.mslScope: MslScope get() { if (!this.isMsl()) return MslScope.NONE diff --git a/src/test/kotlin/org/move/lang/resolve/ResolveTypesTest.kt b/src/test/kotlin/org/move/lang/resolve/ResolveTypesTest.kt index bc0184b07..41d74f54f 100644 --- a/src/test/kotlin/org/move/lang/resolve/ResolveTypesTest.kt +++ b/src/test/kotlin/org/move/lang/resolve/ResolveTypesTest.kt @@ -279,4 +279,15 @@ class ResolveTypesTest : ResolveTestCase() { //^ } """) + +// fun `test resolve type parameters in specs`() = checkByCode(""" +// module 0x1::main { +// fun call(a: u8, b: u8) {} +// //X +// } +// spec 0x1::main { +// spec call(a: u8, b: u8) {} +// //^ +// } +// """) } diff --git a/src/test/kotlin/org/move/lang/resolve/ResolveVariablesTest.kt b/src/test/kotlin/org/move/lang/resolve/ResolveVariablesTest.kt index 25c931be8..d71e31875 100644 --- a/src/test/kotlin/org/move/lang/resolve/ResolveVariablesTest.kt +++ b/src/test/kotlin/org/move/lang/resolve/ResolveVariablesTest.kt @@ -226,4 +226,15 @@ class ResolveVariablesTest : ResolveTestCase() { } } """) +// +// fun `test resolve function parameters in specs`() = checkByCode(""" +// module 0x1::main { +// fun call(a: u8, b: u8) {} +// //X +// } +// spec 0x1::main { +// spec call(a: u8, b: u8) {} +// //^ +// } +// """) } diff --git a/src/test/kotlin/org/move/lang/types/ExpressionTypesTest.kt b/src/test/kotlin/org/move/lang/types/ExpressionTypesTest.kt index 67018a90a..d77f42c25 100644 --- a/src/test/kotlin/org/move/lang/types/ExpressionTypesTest.kt +++ b/src/test/kotlin/org/move/lang/types/ExpressionTypesTest.kt @@ -527,4 +527,46 @@ class ExpressionTypesTest: TypificationTestCase() { } } """) + + fun `test vector lit with explicit type`() = testExpr(""" + module 0x1::main { + fun main() { + let vv = vector[]; + vv; + //^ vector + } + } + """) + + fun `test vector lit with inferred type`() = testExpr(""" + module 0x1::main { + fun main() { + let vv = vector[1u8]; + vv; + //^ vector + } + } + """) + + fun `test vector lit with inferred integer type`() = testExpr(""" + module 0x1::main { + fun main() { + let vv = vector[1]; + vv; + //^ vector + } + } + """) + + fun `test vector lit with inferred type from call expr`() = testExpr(""" + module 0x1::main { + fun call(a: vector) {} + fun main() { + let vv = vector[]; + call(vv); + vv; + //^ vector + } + } + """) } diff --git a/src/test/resources/org/move/lang/parser/partial/spec.txt b/src/test/resources/org/move/lang/parser/partial/spec.txt index 2cb0f60ca..dca957deb 100644 --- a/src/test/resources/org/move/lang/parser/partial/spec.txt +++ b/src/test/resources/org/move/lang/parser/partial/spec.txt @@ -20,7 +20,7 @@ FILE PsiWhiteSpace(' ') MvItemSpecRefImpl(ITEM_SPEC_REF) PsiElement(IDENTIFIER)('my_function') - PsiErrorElement:'{' expected, got 'spec' + PsiErrorElement:'(', ':', < or '{' expected, got 'spec' PsiWhiteSpace('\n ') MvItemSpecImpl(ITEM_SPEC) @@ -28,7 +28,7 @@ FILE PsiWhiteSpace(' ') MvItemSpecRefImpl(ITEM_SPEC_REF) PsiElement(IDENTIFIER)('MyStruct') - PsiErrorElement:'{' expected, got 'spec' + PsiErrorElement:'(', ':', < or '{' expected, got 'spec' PsiWhiteSpace('\n ') MvItemSpecImpl(ITEM_SPEC) @@ -36,7 +36,7 @@ FILE PsiWhiteSpace(' ') MvItemSpecRefImpl(ITEM_SPEC_REF) PsiElement(module_kw)('module') - PsiErrorElement:'{' expected, got 'spec' + PsiErrorElement:'(', ':', < or '{' expected, got 'spec' PsiWhiteSpace('\n ') MvSpecFunctionImpl(SPEC_FUNCTION) diff --git a/src/test/resources/org/move/lang/parser/specs/scopes.move b/src/test/resources/org/move/lang/parser/specs/scopes.move index 525667ef7..6a7d0ad3d 100644 --- a/src/test/resources/org/move/lang/parser/specs/scopes.move +++ b/src/test/resources/org/move/lang/parser/specs/scopes.move @@ -18,7 +18,12 @@ module M { spec native fun spec_is_valid_native(addr: address); fun unpack() {} + spec unpack {} + spec unpack() {} + spec unpack() {} + spec unpack(a: u8, b: u8) {} + spec unpack(): u8 {} spec schema ModuleInvariant {} } diff --git a/src/test/resources/org/move/lang/parser/specs/scopes.txt b/src/test/resources/org/move/lang/parser/specs/scopes.txt index bed9dae07..4d444ffa0 100644 --- a/src/test/resources/org/move/lang/parser/specs/scopes.txt +++ b/src/test/resources/org/move/lang/parser/specs/scopes.txt @@ -215,12 +215,97 @@ FILE MvCodeBlockImpl(CODE_BLOCK) PsiElement({)('{') PsiElement(})('}') + PsiWhiteSpace('\n\n ') + MvItemSpecImpl(ITEM_SPEC) + PsiElement(spec)('spec') + PsiWhiteSpace(' ') + MvItemSpecRefImpl(ITEM_SPEC_REF) + PsiElement(IDENTIFIER)('unpack') + PsiWhiteSpace(' ') + MvItemSpecBlockImpl(ITEM_SPEC_BLOCK) + PsiElement({)('{') + PsiElement(})('}') PsiWhiteSpace('\n ') MvItemSpecImpl(ITEM_SPEC) PsiElement(spec)('spec') PsiWhiteSpace(' ') MvItemSpecRefImpl(ITEM_SPEC_REF) PsiElement(IDENTIFIER)('unpack') + MvItemSpecFunctionParameterListImpl(ITEM_SPEC_FUNCTION_PARAMETER_LIST) + PsiElement(()('(') + PsiElement())(')') + PsiWhiteSpace(' ') + MvItemSpecBlockImpl(ITEM_SPEC_BLOCK) + PsiElement({)('{') + PsiElement(})('}') + PsiWhiteSpace('\n ') + MvItemSpecImpl(ITEM_SPEC) + PsiElement(spec)('spec') + PsiWhiteSpace(' ') + MvItemSpecRefImpl(ITEM_SPEC_REF) + PsiElement(IDENTIFIER)('unpack') + MvItemSpecTypeParameterListImpl(ITEM_SPEC_TYPE_PARAMETER_LIST) + PsiElement(<)('<') + MvItemSpecTypeParameterImpl(ITEM_SPEC_TYPE_PARAMETER) + PsiElement(IDENTIFIER)('T') + PsiElement(,)(',') + PsiWhiteSpace(' ') + MvItemSpecTypeParameterImpl(ITEM_SPEC_TYPE_PARAMETER) + PsiElement(IDENTIFIER)('U') + PsiElement(>)('>') + MvItemSpecFunctionParameterListImpl(ITEM_SPEC_FUNCTION_PARAMETER_LIST) + PsiElement(()('(') + PsiElement())(')') + PsiWhiteSpace(' ') + MvItemSpecBlockImpl(ITEM_SPEC_BLOCK) + PsiElement({)('{') + PsiElement(})('}') + PsiWhiteSpace('\n ') + MvItemSpecImpl(ITEM_SPEC) + PsiElement(spec)('spec') + PsiWhiteSpace(' ') + MvItemSpecRefImpl(ITEM_SPEC_REF) + PsiElement(IDENTIFIER)('unpack') + MvItemSpecFunctionParameterListImpl(ITEM_SPEC_FUNCTION_PARAMETER_LIST) + PsiElement(()('(') + MvItemSpecFunctionParameterImpl(ITEM_SPEC_FUNCTION_PARAMETER) + PsiElement(IDENTIFIER)('a') + MvTypeAnnotationImpl(TYPE_ANNOTATION) + PsiElement(:)(':') + PsiWhiteSpace(' ') + MvPathTypeImpl(PATH_TYPE) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('u8') + PsiElement(,)(',') + PsiWhiteSpace(' ') + MvItemSpecFunctionParameterImpl(ITEM_SPEC_FUNCTION_PARAMETER) + PsiElement(IDENTIFIER)('b') + MvTypeAnnotationImpl(TYPE_ANNOTATION) + PsiElement(:)(':') + PsiWhiteSpace(' ') + MvPathTypeImpl(PATH_TYPE) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('u8') + PsiElement())(')') + PsiWhiteSpace(' ') + MvItemSpecBlockImpl(ITEM_SPEC_BLOCK) + PsiElement({)('{') + PsiElement(})('}') + PsiWhiteSpace('\n ') + MvItemSpecImpl(ITEM_SPEC) + PsiElement(spec)('spec') + PsiWhiteSpace(' ') + MvItemSpecRefImpl(ITEM_SPEC_REF) + PsiElement(IDENTIFIER)('unpack') + MvItemSpecFunctionParameterListImpl(ITEM_SPEC_FUNCTION_PARAMETER_LIST) + PsiElement(()('(') + PsiElement())(')') + MvReturnTypeImpl(RETURN_TYPE) + PsiElement(:)(':') + PsiWhiteSpace(' ') + MvPathTypeImpl(PATH_TYPE) + MvPathImpl(PATH) + PsiElement(IDENTIFIER)('u8') PsiWhiteSpace(' ') MvItemSpecBlockImpl(ITEM_SPEC_BLOCK) PsiElement({)('{') From b3201ca8e0cd5d071552c6b231b3f917158b1957 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Sun, 18 Sep 2022 00:21:44 +0200 Subject: [PATCH 13/26] type check vector literals, type check call exprs with not enough arguments --- changelog/1.20.0.md | 4 + gradle.properties | 2 +- src/main/grammars/MoveParser.bnf | 5 + src/main/kotlin/org/move/cli/MovePackage.kt | 6 +- .../move/ide/docs/MvDocumentationProvider.kt | 4 +- .../hints/type/MvInlayTypeHintsProvider.kt | 4 +- .../ide/inspections/MvTypeCheckInspection.kt | 98 ++----- .../lang/core/completion/LookupElements.kt | 4 +- .../providers/ModulesCompletionProvider.kt | 3 - .../providers/MvPathCompletionProvider.kt | 4 +- .../org/move/lang/core/psi/MvFunctionLike.kt | 9 +- .../org/move/lang/core/psi/ext/MoveExpr.kt | 4 +- .../lang/core/psi/ext/MvAttrItemArgument.kt | 2 +- .../org/move/lang/core/psi/ext/MvItemSpec.kt | 15 +- .../move/lang/core/psi/ext/MvItemSpecRef.kt | 19 ++ .../move/lang/core/psi/ext/MvSpecFunction.kt | 3 + .../move/lang/core/resolve/NameResolution.kt | 4 +- .../lang/core/types/infer/ExpectedType.kt | 6 +- .../move/lang/core/types/infer/Expressions.kt | 57 ++-- .../lang/core/types/infer/InferenceContext.kt | 132 +++++---- .../org/move/lang/core/types/ty/TyFunction.kt | 2 - .../utils/tests/types/TypificationTestCase.kt | 4 +- .../inspections/MvTypeCheckInspectionTest.kt | 266 ++++++++++-------- .../move/lang/types/ExpressionTypesTest.kt | 56 ++++ 24 files changed, 417 insertions(+), 296 deletions(-) create mode 100644 src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpecRef.kt diff --git a/changelog/1.20.0.md b/changelog/1.20.0.md index 91132b1ce..7f796fe17 100644 --- a/changelog/1.20.0.md +++ b/changelog/1.20.0.md @@ -20,6 +20,10 @@ TODO: screenshot * Allow repeating function signature in spec for readability. +* Type inference support for vector literals. + +* Type check calls with not enough arguments. + ## Fixes * Allow spaces inside `public(friend)` function modifier. diff --git a/gradle.properties b/gradle.properties index eba3e1e23..163aa24eb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,4 +14,4 @@ propertiesPluginEnvironmentNameProperty=shortPlatformVersion # properties files # supported versions are 212, 213, 221, 222, default is 212 # pass ORG_GRADLE_PROJECT_shortPlatformVersion environment variable to overwrite -shortPlatformVersion=212 +shortPlatformVersion=222 diff --git a/src/main/grammars/MoveParser.bnf b/src/main/grammars/MoveParser.bnf index dccf34327..273402440 100644 --- a/src/main/grammars/MoveParser.bnf +++ b/src/main/grammars/MoveParser.bnf @@ -1083,7 +1083,12 @@ ItemSpec ::= spec ItemSpecRef ItemSpecTypeParameterList? ItemSpecFunctionParamet <> { pin = 1 + implements = [ + "org.move.lang.core.types.infer.MvInferenceContextOwner" + ] + mixin = "org.move.lang.core.psi.ext.MvItemSpecMixin" } + ItemSpecTypeParameterList ::= '<' ItemSpecTypeParameter_with_recover* '>' { pin = 1 diff --git a/src/main/kotlin/org/move/cli/MovePackage.kt b/src/main/kotlin/org/move/cli/MovePackage.kt index 98bc2c1c0..39b7a6161 100644 --- a/src/main/kotlin/org/move/cli/MovePackage.kt +++ b/src/main/kotlin/org/move/cli/MovePackage.kt @@ -15,13 +15,13 @@ data class MovePackage( ) { val packageName = this.moveToml.packageName ?: "" - val sourcesFolder: VirtualFile? get() = contentRoot.findChild("sources") - val testsFolder: VirtualFile? get() = contentRoot.findChild("tests") + val sourcesFolder: VirtualFile? get() = contentRoot.takeIf { it.isValid }?.findChild("sources") + val testsFolder: VirtualFile? get() = contentRoot.takeIf { it.isValid }?.findChild("tests") fun moveFolders(): List = listOfNotNull(sourcesFolder, testsFolder) fun layoutPaths(): List { - val rootPath = contentRoot.toNioPathOrNull() ?: return emptyList() + val rootPath = contentRoot.takeIf { it.isValid }?.toNioPathOrNull() ?: return emptyList() val names = listOf( *MvProjectLayout.sourcesDirs, MvProjectLayout.testsDir, diff --git a/src/main/kotlin/org/move/ide/docs/MvDocumentationProvider.kt b/src/main/kotlin/org/move/ide/docs/MvDocumentationProvider.kt index c0b058be9..e21ecbb2b 100644 --- a/src/main/kotlin/org/move/ide/docs/MvDocumentationProvider.kt +++ b/src/main/kotlin/org/move/ide/docs/MvDocumentationProvider.kt @@ -10,7 +10,7 @@ import org.move.ide.presentation.text import org.move.ide.presentation.typeLabel import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.* -import org.move.lang.core.types.infer.functionInferenceCtx +import org.move.lang.core.types.infer.ownerInferenceCtx import org.move.lang.core.types.ty.Ty import org.move.lang.moveProject import org.move.stdext.joinToWithBuffer @@ -47,7 +47,7 @@ class MvDocumentationProvider : AbstractDocumentationProvider() { is MvDocAndAttributeOwner -> generateOwnerDoc(docElement, buffer) is MvBindingPat -> { val presentationInfo = docElement.presentationInfo ?: return null - val ctx = docElement.functionInferenceCtx(false) + val ctx = docElement.ownerInferenceCtx(false) val type = docElement.inferredTy(ctx).renderForDocs(true) buffer += presentationInfo.type buffer += " " diff --git a/src/main/kotlin/org/move/ide/hints/type/MvInlayTypeHintsProvider.kt b/src/main/kotlin/org/move/ide/hints/type/MvInlayTypeHintsProvider.kt index abbc54ce2..2a2155204 100644 --- a/src/main/kotlin/org/move/ide/hints/type/MvInlayTypeHintsProvider.kt +++ b/src/main/kotlin/org/move/ide/hints/type/MvInlayTypeHintsProvider.kt @@ -14,7 +14,7 @@ import org.move.lang.core.psi.ext.endOffset import org.move.lang.core.psi.ext.inferredTy import org.move.lang.core.psi.ext.isMsl import org.move.lang.core.types.infer.InferenceContext -import org.move.lang.core.types.infer.functionInferenceCtx +import org.move.lang.core.types.infer.ownerInferenceCtx import org.move.lang.core.types.ty.TyUnknown import javax.swing.JComponent import javax.swing.JPanel @@ -91,7 +91,7 @@ class MvInlayTypeHintsProvider : InlayHintsProvider()) { if (binding.identifier.text.startsWith("_")) continue if (binding.inferredTy(ctx) is TyUnknown) continue diff --git a/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt b/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt index 0a9ccbcdf..07b75050a 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt @@ -1,34 +1,17 @@ package org.move.ide.inspections -import com.intellij.codeInspection.LocalQuickFix import com.intellij.codeInspection.ProblemHighlightType import com.intellij.codeInspection.ProblemsHolder import com.intellij.codeInspection.util.InspectionMessage import com.intellij.psi.PsiElement import org.move.ide.presentation.name -import org.move.ide.presentation.typeLabel import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.* -import org.move.lang.core.types.infer.* -import org.move.lang.core.types.ty.Ty -import org.move.lang.core.types.ty.TyFunction +import org.move.lang.core.types.infer.MvInferenceContextOwner +import org.move.lang.core.types.infer.TypeError +import org.move.lang.core.types.infer.inferenceCtx +import org.move.lang.core.types.infer.isCompatible import org.move.lang.core.types.ty.TyStruct -import org.move.lang.core.types.ty.isTypeParam - -fun ProblemsHolder.registerTypeError( - element: PsiElement, - @InspectionMessage message: String, -) { - this.registerProblem(element, message, ProblemHighlightType.GENERIC_ERROR) -} - -fun ProblemsHolder.registerTypeError(typeError: TypeError) { - this.registerProblem( - typeError.element, - typeError.message(), - ProblemHighlightType.GENERIC_ERROR, - ) -} class MvTypeCheckInspection : MvLocalInspectionTool() { override val isSyntaxOnly: Boolean get() = true @@ -48,6 +31,12 @@ class MvTypeCheckInspection : MvLocalInspectionTool() { } } + override fun visitItemSpec(o: MvItemSpec) { + val inference = o.inferenceCtx(true) + inference.typeErrors + .forEach { holder.registerTypeError(it) } + } + override fun visitCodeBlock(codeBlock: MvCodeBlock) { val fn = codeBlock.parent as? MvFunction ?: return val inference = fn.inferenceCtx(fn.isMsl()) @@ -55,40 +44,6 @@ class MvTypeCheckInspection : MvLocalInspectionTool() { .forEach { holder.registerTypeError(it) } } - override fun visitValueArgumentList(callArgs: MvValueArgumentList) { - val callExpr = callArgs.parent as? MvCallExpr ?: return - val function = callExpr.path.reference?.resolve() as? MvFunctionLike ?: return - - if (function.parameters.size != callArgs.valueArgumentList.size) return - - val inferenceCtx = callArgs.functionInferenceCtx(callArgs.isMsl()) - val callTy = inferenceCtx.callExprTypes - .getOrElse(callExpr) { - inferCallExprTy(callExpr, inferenceCtx, null) as? TyFunction - } ?: return - - for ((i, expr) in callArgs.argumentExprs.withIndex()) { - val parameter = function.parameters[i] - val paramTy = callTy.paramTypes[i] - val exprTy = expr.inferredTy() - - if (paramTy.isTypeParam || exprTy.isTypeParam) { - val abilitiesErrorCreated = checkHasRequiredAbilities(holder, expr, exprTy, paramTy) - if (abilitiesErrorCreated) continue - } - - if (!isCompatible(paramTy, exprTy)) { - val paramName = parameter.bindingPat.name ?: continue - val exprTypeName = exprTy.name() - val expectedTypeName = paramTy.name() - val message = - "Invalid argument for parameter '$paramName': " + - "type '$exprTypeName' is not compatible with '$expectedTypeName'" - holder.registerTypeError(expr, message) - } - } - } - override fun visitStructField(field: MvStructField) { val msl = field.isMsl() val structAbilities = field.struct.tyAbilities @@ -108,28 +63,19 @@ class MvTypeCheckInspection : MvLocalInspectionTool() { } } } -} -private fun checkHasRequiredAbilities( - holder: ProblemsHolder, - element: MvElement, - actualTy: Ty, - expectedTy: Ty -): Boolean { - // do not check for specs - if (element.isMsl()) return false + fun ProblemsHolder.registerTypeError( + element: PsiElement, + @InspectionMessage message: String, + ) { + this.registerProblem(element, message, ProblemHighlightType.GENERIC_ERROR) + } - val abilities = actualTy.abilities() - for (ability in expectedTy.abilities()) { - if (ability !in abilities) { - val typeName = actualTy.typeLabel(relativeTo = element) - holder.registerTypeError( - element, - "The type '$typeName' " + - "does not have required ability '${ability.label()}'" - ) - return true - } + fun ProblemsHolder.registerTypeError(typeError: TypeError) { + this.registerProblem( + typeError.element, + typeError.message(), + ProblemHighlightType.GENERIC_ERROR, + ) } - return false } diff --git a/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt b/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt index b25604b55..ddfd80f9d 100644 --- a/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt +++ b/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt @@ -13,7 +13,7 @@ import org.move.lang.core.resolve.ItemVis import org.move.lang.core.resolve.ref.Namespace import org.move.lang.core.types.infer.InferenceContext import org.move.lang.core.types.infer.containsTyOfClass -import org.move.lang.core.types.infer.functionInferenceCtx +import org.move.lang.core.types.infer.ownerInferenceCtx import org.move.lang.core.types.infer.instantiateItemTy import org.move.lang.core.types.ty.Ty import org.move.lang.core.types.ty.TyFunction @@ -105,7 +105,7 @@ fun MvNamedElement.createBaseLookupElement(ns: Set): LookupElementBui .withTypeText(this.typeAnnotation?.type?.text) is MvBindingPat -> this.createLookupElementWithIcon() - .withTypeText(this.inferredTy(this.functionInferenceCtx(this.isMsl())).text(true)) + .withTypeText(this.inferredTy(this.ownerInferenceCtx(this.isMsl())).text(true)) is MvSchema -> this.createLookupElementWithIcon() .withTypeText(this.containingFile?.name) diff --git a/src/main/kotlin/org/move/lang/core/completion/providers/ModulesCompletionProvider.kt b/src/main/kotlin/org/move/lang/core/completion/providers/ModulesCompletionProvider.kt index bc65b257f..3a74eb2f4 100644 --- a/src/main/kotlin/org/move/lang/core/completion/providers/ModulesCompletionProvider.kt +++ b/src/main/kotlin/org/move/lang/core/completion/providers/ModulesCompletionProvider.kt @@ -37,9 +37,6 @@ object ModulesCompletionProvider : MvCompletionProvider() { if (parameters.position !== refElement.referenceNameElement) return if (refElement.moduleRef != null) return -// val props = LookupElementProperties( -// isCompatibleWithContext = maybePath.parent !is MvPathType -// ) val processedNames = mutableSetOf() val itemVis = ItemVis( diff --git a/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider.kt b/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider.kt index 9e82e5cb4..5ba2f8132 100644 --- a/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider.kt +++ b/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider.kt @@ -21,7 +21,7 @@ import org.move.lang.core.resolve.ref.Namespace import org.move.lang.core.resolve.ref.Visibility import org.move.lang.core.resolve.ref.processModuleItems import org.move.lang.core.types.infer.InferenceContext -import org.move.lang.core.types.infer.functionInferenceCtx +import org.move.lang.core.types.infer.ownerInferenceCtx import org.move.lang.core.types.infer.inferExpectedTy import org.move.lang.core.types.ty.Ty @@ -41,7 +41,7 @@ abstract class MvPathCompletionProvider : MvCompletionProvider() { val moduleRef = pathElement.moduleRef val itemVis = itemVis(pathElement) - val inferenceCtx = pathElement.functionInferenceCtx() + val inferenceCtx = pathElement.ownerInferenceCtx() val expectedTy = getExpectedTypeForEnclosingPathOrDotExpr(pathElement, inferenceCtx) val ctx = CompletionContext(pathElement, itemVis, expectedTy) diff --git a/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt b/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt index 243466c2f..a06e2de9e 100644 --- a/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt +++ b/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt @@ -5,6 +5,7 @@ import org.move.lang.core.psi.ext.MvDocAndAttributeOwner import org.move.lang.core.psi.ext.hasChild import org.move.lang.core.psi.ext.ty import org.move.lang.core.psi.mixins.declaredTy +import org.move.lang.core.types.infer.MvInferenceContextOwner import org.move.lang.core.types.infer.foldTyTypeParameterWith import org.move.lang.core.types.ty.Ty import org.move.lang.core.types.ty.TyUnit @@ -14,19 +15,21 @@ import org.move.stdext.wrapWithList interface MvFunctionLike : MvTypeParametersOwner, MvNameIdentifierOwner, - MvDocAndAttributeOwner { + MvDocAndAttributeOwner, + MvInferenceContextOwner { val functionParameterList: MvFunctionParameterList? val returnType: MvReturnType? + + override fun parameterBindings(): List = + this.functionParameterList?.functionParameterList.orEmpty().map { it.bindingPat } } val MvFunctionLike.isNative get() = hasChild(MvElementTypes.NATIVE) val MvFunctionLike.parameters get() = this.functionParameterList?.functionParameterList.orEmpty() -val MvFunctionLike.parameterBindings: List get() = this.parameters.map { it.bindingPat } - val MvFunctionLike.returnTy: Ty get() { val returnTypeElement = this.returnType diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MoveExpr.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MoveExpr.kt index 83acf2384..bbdbd4666 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MoveExpr.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MoveExpr.kt @@ -1,13 +1,13 @@ package org.move.lang.core.psi.ext import org.move.lang.core.psi.MvExpr -import org.move.lang.core.types.infer.functionInferenceCtx +import org.move.lang.core.types.infer.ownerInferenceCtx import org.move.lang.core.types.infer.inferExprTy import org.move.lang.core.types.ty.Ty fun MvExpr.inferredTy(): Ty { val msl = this.isMsl() - val inferenceCtx = this.functionInferenceCtx(msl) + val inferenceCtx = this.ownerInferenceCtx(msl) val existingTy = inferenceCtx.exprTypes[this] if (existingTy != null) { diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvAttrItemArgument.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvAttrItemArgument.kt index 662b2391a..3954c7087 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvAttrItemArgument.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvAttrItemArgument.kt @@ -11,7 +11,7 @@ class AttrItemArgumentReferenceImpl( ) : MvReferenceCached(element) { override fun resolveInner(): List { - return ownerFunction.parameterBindings + return ownerFunction.parameterBindings() .filter { it.name == element.referenceName } } } diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpec.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpec.kt index 4aa7b059a..3ab2902f4 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpec.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpec.kt @@ -1,11 +1,7 @@ package org.move.lang.core.psi.ext import com.intellij.lang.ASTNode -import com.intellij.psi.PsiElement -import org.move.lang.MvElementTypes.MODULE_KW import org.move.lang.core.psi.* -import org.move.lang.core.resolve.ref.MvItemSpecRefReferenceImpl -import org.move.lang.core.resolve.ref.MvReference val MvItemSpec.item: MvNamedElement? get() = this.itemSpecRef?.reference?.resolve() @@ -14,12 +10,9 @@ val MvItemSpec.structItem get() = this.item as? MvStruct val MvItemSpec.itemSpecBlock: MvItemSpecBlock? get() = this.childOfType() -val MvItemSpecRef.moduleKw: PsiElement? get() = this.findFirstChildByType(MODULE_KW) - -abstract class MvItemSpecRefMixin(node: ASTNode) : MvElementImpl(node), MvItemSpecRef { - override fun getReference(): MvReference? { - return if (this.moduleKw != null) null - else - MvItemSpecRefReferenceImpl(this) +abstract class MvItemSpecMixin(node: ASTNode) : MvElementImpl(node), + MvItemSpec { + override fun parameterBindings(): List { + return this.funcItem?.parameterBindings().orEmpty() } } diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpecRef.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpecRef.kt new file mode 100644 index 000000000..3b1a21c18 --- /dev/null +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpecRef.kt @@ -0,0 +1,19 @@ +package org.move.lang.core.psi.ext + +import com.intellij.lang.ASTNode +import com.intellij.psi.PsiElement +import org.move.lang.MvElementTypes +import org.move.lang.core.psi.MvElementImpl +import org.move.lang.core.psi.MvItemSpecRef +import org.move.lang.core.resolve.ref.MvItemSpecRefReferenceImpl +import org.move.lang.core.resolve.ref.MvReference + +val MvItemSpecRef.moduleKw: PsiElement? get() = this.findFirstChildByType(MvElementTypes.MODULE_KW) + +abstract class MvItemSpecRefMixin(node: ASTNode) : MvElementImpl(node), MvItemSpecRef { + override fun getReference(): MvReference? { + return if (this.moduleKw != null) null + else + MvItemSpecRefReferenceImpl(this) + } +} diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvSpecFunction.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvSpecFunction.kt index c61132268..2c552d5a2 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvSpecFunction.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvSpecFunction.kt @@ -2,15 +2,18 @@ package org.move.lang.core.psi.ext import com.intellij.lang.ASTNode import org.move.ide.MoveIcons +import org.move.lang.core.psi.MvBindingPat import org.move.lang.core.psi.MvSpecFunction import org.move.lang.core.psi.MvSpecInlineFunction import org.move.lang.core.psi.impl.MvNameIdentifierOwnerImpl +import org.move.lang.core.psi.parameters import javax.swing.Icon abstract class MvSpecFunctionMixin(node: ASTNode) : MvNameIdentifierOwnerImpl(node), MvSpecFunction { override fun getIcon(flags: Int): Icon = MoveIcons.FUNCTION + } abstract class MvSpecInlineFunctionMixin(node: ASTNode) : MvNameIdentifierOwnerImpl(node), diff --git a/src/main/kotlin/org/move/lang/core/resolve/NameResolution.kt b/src/main/kotlin/org/move/lang/core/resolve/NameResolution.kt index de9ab7f07..17aba85f9 100644 --- a/src/main/kotlin/org/move/lang/core/resolve/NameResolution.kt +++ b/src/main/kotlin/org/move/lang/core/resolve/NameResolution.kt @@ -241,7 +241,7 @@ fun processLexicalDeclarations( ) is MvScriptBlock -> processor.matchAll(itemVis, scope.itemImportNames()) is MvScript -> processor.matchAll(itemVis, scope.constBindings()) - is MvFunctionLike -> processor.matchAll(itemVis, scope.parameterBindings) + is MvFunctionLike -> processor.matchAll(itemVis, scope.parameterBindings()) is MvCodeBlock -> { val precedingLetDecls = scope.letStmts // drops all let-statements after the current position @@ -266,7 +266,7 @@ fun processLexicalDeclarations( is MvItemSpec -> { val item = scope.item when (item) { - is MvFunction -> processor.matchAll(itemVis, item.parameterBindings) + is MvFunction -> processor.matchAll(itemVis, item.parameterBindings()) is MvStruct -> processor.matchAll(itemVis, item.fields) else -> false } diff --git a/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt b/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt index c60651b7f..3f58124f5 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt @@ -24,13 +24,13 @@ fun inferExpectedTy(element: PsiElement, ctx: InferenceContext): Ty? { val ownerExpr = path.parent when (ownerExpr) { is MvCallExpr -> { - val inferenceCtx = ownerExpr.functionInferenceCtx(ownerExpr.isMsl()) + val inferenceCtx = ownerExpr.ownerInferenceCtx(ownerExpr.isMsl()) inferenceCtx.callExprTypes[ownerExpr] ?.typeVars ?.getOrNull(paramIndex) } is MvStructLitExpr -> { - val inferenceCtx = ownerExpr.functionInferenceCtx(ownerExpr.isMsl()) + val inferenceCtx = ownerExpr.ownerInferenceCtx(ownerExpr.isMsl()) (inferenceCtx.exprTypes[ownerExpr] as? TyStruct) ?.typeArgs ?.getOrNull(paramIndex) @@ -44,7 +44,7 @@ fun inferExpectedTy(element: PsiElement, ctx: InferenceContext): Ty? { valueArgumentList.children.indexOfFirst { it.textRange.contains(owner.textOffset) } if (paramIndex == -1) return null val callExpr = valueArgumentList.parent as? MvCallExpr ?: return null - val inferenceCtx = callExpr.functionInferenceCtx(callExpr.isMsl()) + val inferenceCtx = callExpr.ownerInferenceCtx(callExpr.isMsl()) inferenceCtx.callExprTypes[callExpr] ?.paramTypes ?.getOrNull(paramIndex) diff --git a/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt b/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt index 7313edcc6..cdd2260e8 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt @@ -59,10 +59,15 @@ fun inferExprTy(expr: MvExpr, parentCtx: InferenceContext, expectedTy: Ty? = nul exprTy = TyNum } if (expectedTy != null) { - if (!isCompatible(expectedTy, exprTy, parentCtx.msl)) { - parentCtx.typeErrors.add(TypeError.TypeMismatch(expr, expectedTy, exprTy)) - } else { - parentCtx.addConstraint(exprTy, expectedTy) + val compat = checkTysCompatible(expectedTy, exprTy, parentCtx.msl) + when (compat) { + is Compat.AbilitiesMismatch -> { + parentCtx.typeErrors.add(TypeError.AbilitiesMismatch(expr, exprTy, compat.abilities)) + } + is Compat.TypeMismatch -> { + parentCtx.typeErrors.add(TypeError.TypeMismatch(expr, expectedTy, exprTy)) + } + else -> parentCtx.addConstraint(exprTy, expectedTy) } } @@ -95,8 +100,8 @@ fun inferCallExprTy( val path = callExpr.path val funcItem = path.reference?.resolve() as? MvFunctionLike ?: return TyUnknown - val funcTy = instantiateItemTy(funcItem, parentCtx.msl) as? TyFunction ?: return TyUnknown + var funcTy = instantiateItemTy(funcItem, parentCtx.msl) as? TyFunction ?: return TyUnknown val inferenceCtx = InferenceContext(parentCtx.msl) // find all types passed as explicit type parameters, create constraints with those if (path.typeArguments.isNotEmpty()) { @@ -124,24 +129,23 @@ fun inferCallExprTy( } } // find all types of passed expressions, create constraints with those - if (callExpr.callArgumentExprs.isNotEmpty()) { - for ((paramTy, argumentExpr) in funcTy.paramTypes.zip(callExpr.callArgumentExprs)) { - val argumentExprTy = inferExprTy(argumentExpr, parentCtx) - inferenceCtx.addConstraint(paramTy, argumentExprTy) - } + for ((i, argumentExpr) in callExpr.callArgumentExprs.withIndex()) { + inferenceCtx.processConstraints() + funcTy = inferenceCtx.resolveTy(funcTy) as TyFunction + + val paramTy = funcTy.paramTypes.getOrNull(i) ?: break + val argumentExprTy = inferExprTy(argumentExpr, parentCtx, paramTy) + inferenceCtx.addConstraint(paramTy, argumentExprTy) } if (expectedTy != null) { inferenceCtx.addConstraint(funcTy.retType, expectedTy) } - // solve constraints - val solvable = inferenceCtx.processConstraints() - val resolvedFuncTy = inferenceCtx.resolveTy(funcTy) as TyFunction - resolvedFuncTy.solvable = solvable + inferenceCtx.processConstraints() + funcTy = inferenceCtx.resolveTy(funcTy) as TyFunction - parentCtx.resolveTyVarsFromContext(inferenceCtx) - parentCtx.cacheCallExprTy(callExpr, resolvedFuncTy) - return resolvedFuncTy + parentCtx.cacheCallExprTy(callExpr, funcTy) + return funcTy } private fun inferDotExprTy(dotExpr: MvDotExpr, parentCtx: InferenceContext): Ty { @@ -257,7 +261,24 @@ fun inferStructPatTy(structPat: MvStructPat, parentCtx: InferenceContext, expect } fun inferVectorLitExpr(litExpr: MvVectorLitExpr, parentCtx: InferenceContext): Ty { - return TyVector(TyUnknown) + var tyVector = TyVector(TyInfer.TyVar()) + val inferenceCtx = InferenceContext(litExpr.isMsl()) + val typeArgument = litExpr.typeArgument + if (typeArgument != null) { + val ty = inferTypeTy(typeArgument.type, litExpr.isMsl()) + inferenceCtx.addConstraint(tyVector.item, ty) + } + val exprs = litExpr.vectorLitItems.exprList + for (expr in exprs) { + inferenceCtx.processConstraints() + tyVector = inferenceCtx.resolveTy(tyVector) as TyVector + + val exprTy = inferExprTy(expr, parentCtx, tyVector.item) + inferenceCtx.addConstraint(tyVector.item, exprTy) + } + inferenceCtx.processConstraints() + tyVector = inferenceCtx.resolveTy(tyVector) as TyVector + return tyVector } fun inferLitFieldInitExprTy(litField: MvStructLitField, ctx: InferenceContext, expectedTy: Ty?): Ty { diff --git a/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt b/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt index 3c0ebcbe0..3046e2dd9 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt @@ -1,9 +1,8 @@ package org.move.lang.core.types.infer -import com.intellij.openapi.util.Key import com.intellij.psi.PsiElement -import com.intellij.psi.util.CachedValue import com.intellij.psi.util.CachedValuesManager.getProjectPsiDependentCache +import com.intellij.psi.util.PsiTreeUtil import com.jetbrains.rd.util.concurrentMapOf import org.move.ide.presentation.expectedBindingFormText import org.move.ide.presentation.name @@ -13,46 +12,47 @@ import org.move.lang.core.psi.ext.* import org.move.lang.core.psi.mixins.ty import org.move.lang.core.types.ty.* -fun MvElement.functionInferenceCtx(msl: Boolean = this.isMsl()): InferenceContext { - return this.containingFunctionLike?.inferenceCtx(msl) ?: InferenceContext(msl) +interface MvInferenceContextOwner: MvElement { + fun parameterBindings(): List } -fun MvFunctionLike.inferenceCtx(msl: Boolean): InferenceContext { +fun MvInferenceContextOwner.inferenceCtx(msl: Boolean): InferenceContext { return if (msl) { getProjectPsiDependentCache(this) { - getInferenceContext(it, true) + getOwnerInferenceContext(it, true) } } else { getProjectPsiDependentCache(this) { - getInferenceContext(it, false) + getOwnerInferenceContext(it, false) } } } -private fun getInferenceContext(owner: MvFunctionLike, msl: Boolean): InferenceContext { - val functionCtx = InferenceContext(msl) - for (param in owner.parameterBindings) { - functionCtx.bindingTypes[param] = param.inferredTy(functionCtx) +fun MvElement.ownerInferenceCtx(msl: Boolean = this.isMsl()): InferenceContext { + val inferenceOwner = + PsiTreeUtil.getParentOfType(this, MvInferenceContextOwner::class.java, false) + return inferenceOwner?.inferenceCtx(msl) ?: InferenceContext(msl) +} + +private fun getOwnerInferenceContext(owner: MvInferenceContextOwner, msl: Boolean): InferenceContext { + val inferenceCtx = InferenceContext(msl) + for (param in owner.parameterBindings()) { + inferenceCtx.bindingTypes[param] = param.inferredTy(inferenceCtx) } - if (owner is MvFunction) { - owner.codeBlock?.let { inferCodeBlockTy(it, functionCtx, owner.returnTy) } + when (owner) { + is MvFunction -> { + owner.codeBlock?.let { inferCodeBlockTy(it, inferenceCtx, owner.returnTy) } + } + is MvItemSpec -> { + owner.itemSpecBlock?.let { inferSpecBlockStmts(it, inferenceCtx) } + } } - return functionCtx + return inferenceCtx } fun inferCodeBlockTy(block: MvCodeBlock, blockCtx: InferenceContext, expectedTy: Ty?): Ty { for (stmt in block.stmtList) { - when (stmt) { - is MvExprStmt -> inferExprTy(stmt.expr, blockCtx) - is MvLetStmt -> { -// val explicitTy = stmt.declaredTy - val explicitTy = stmt.typeAnnotation?.type?.let { inferTypeTy(it, stmt.isMsl()) } - val initializerTy = stmt.initializer?.expr?.let { inferExprTy(it, blockCtx, explicitTy) } - val pat = stmt.pat ?: continue - val patTy = inferPatTy(pat, blockCtx, explicitTy ?: initializerTy) - collectBindings(pat, patTy, blockCtx) - } - } + inferStmt(stmt, blockCtx) blockCtx.processConstraints() blockCtx.resolveTyVarsFromContext(blockCtx) } @@ -77,6 +77,28 @@ fun inferCodeBlockTy(block: MvCodeBlock, blockCtx: InferenceContext, expectedTy: } } +fun inferSpecBlockStmts(block: MvItemSpecBlock, blockCtx: InferenceContext) { + for (stmt in block.stmtList) { + inferStmt(stmt, blockCtx) + blockCtx.processConstraints() + blockCtx.resolveTyVarsFromContext(blockCtx) + } +} + +fun inferStmt(stmt: MvStmt, blockCtx: InferenceContext) { + when (stmt) { + is MvExprStmt -> inferExprTy(stmt.expr, blockCtx) + is MvSpecExprStmt -> inferExprTy(stmt.expr, blockCtx) + is MvLetStmt -> { + val explicitTy = stmt.typeAnnotation?.type?.let { inferTypeTy(it, stmt.isMsl()) } + val initializerTy = stmt.initializer?.expr?.let { inferExprTy(it, blockCtx, explicitTy) } + val pat = stmt.pat ?: return + val patTy = inferPatTy(pat, blockCtx, explicitTy ?: initializerTy) + collectBindings(pat, patTy, blockCtx) + } + } +} + fun instantiateItemTy(item: MvNameIdentifierOwner, msl: Boolean): Ty { return when (item) { is MvStruct -> { @@ -134,25 +156,36 @@ fun instantiateItemTy(item: MvNameIdentifierOwner, msl: Boolean): Ty { } } -fun isCompatibleReferences(expectedTy: TyReference, inferredTy: TyReference, msl: Boolean): Boolean { - return isCompatible(expectedTy.referenced, inferredTy.referenced, msl) +fun isCompatibleReferences(expectedTy: TyReference, inferredTy: TyReference, msl: Boolean): Compat { + return checkTysCompatible(expectedTy.referenced, inferredTy.referenced, msl) } -fun isCompatibleStructs(expectedTy: TyStruct, inferredTy: TyStruct, msl: Boolean): Boolean { - return expectedTy.item.fqName == inferredTy.item.fqName +fun isCompatibleStructs(expectedTy: TyStruct, inferredTy: TyStruct, msl: Boolean): Compat { + val isCompat = expectedTy.item.fqName == inferredTy.item.fqName && expectedTy.typeArgs.size == inferredTy.typeArgs.size && expectedTy.typeArgs.zip(inferredTy.typeArgs).all { isCompatible(it.first, it.second, msl) } + return if (isCompat) { + Compat.Yes + } else { + Compat.TypeMismatch(expectedTy, inferredTy) + } } -fun isCompatibleTuples(expectedTy: TyTuple, inferredTy: TyTuple, msl: Boolean): Boolean { - return expectedTy.types.size == inferredTy.types.size +fun isCompatibleTuples(expectedTy: TyTuple, inferredTy: TyTuple, msl: Boolean): Compat { + val isCompat = expectedTy.types.size == inferredTy.types.size && expectedTy.types.zip(inferredTy.types).all { isCompatible(it.first, it.second, msl) } + return if (isCompat) Compat.Yes else Compat.TypeMismatch(expectedTy, inferredTy) } -fun isCompatibleIntegers(expectedTy: TyInteger, inferredTy: TyInteger): Boolean { - return expectedTy.kind == TyInteger.DEFAULT_KIND +fun isCompatibleIntegers(expectedTy: TyInteger, inferredTy: TyInteger): Compat { + val isCompat = expectedTy.kind == TyInteger.DEFAULT_KIND || inferredTy.kind == TyInteger.DEFAULT_KIND || expectedTy.kind == inferredTy.kind + return if (isCompat) { + Compat.Yes + } else { + Compat.TypeMismatch(expectedTy, inferredTy) + } } /// find common denominator for both types @@ -170,40 +203,44 @@ fun combineTys(ty1: Ty, ty2: Ty, msl: Boolean): Ty { } fun isCompatible(rawExpectedTy: Ty, rawInferredTy: Ty, msl: Boolean = true): Boolean { + val compat = checkTysCompatible(rawExpectedTy, rawInferredTy, msl) + return compat == Compat.Yes +} + +fun checkTysCompatible(rawExpectedTy: Ty, rawInferredTy: Ty, msl: Boolean = true): Compat { val expectedTy = rawExpectedTy.mslTy() val inferredTy = rawInferredTy.mslTy() return when { - expectedTy is TyNever || inferredTy is TyNever -> true - expectedTy is TyUnknown || inferredTy is TyUnknown -> true + expectedTy is TyNever || inferredTy is TyNever -> Compat.Yes + expectedTy is TyUnknown || inferredTy is TyUnknown -> Compat.Yes expectedTy is TyInfer.TyVar -> { - val compat = isCompatibleAbilities(expectedTy, inferredTy, msl) - compat == Compat.Yes + isCompatibleAbilities(expectedTy, inferredTy, msl) } /* expectedTy !is TyInfer.TyVar && */ inferredTy is TyInfer.TyVar -> { // todo: should always be false // todo: can it ever occur anyway? - true + Compat.Yes } expectedTy is TyInfer.IntVar && (inferredTy is TyInfer.IntVar || inferredTy is TyInteger) -> { - true + Compat.Yes } inferredTy is TyInfer.IntVar && expectedTy is TyInteger -> { - true + Compat.Yes } expectedTy is TyTypeParameter || inferredTy is TyTypeParameter -> { // check abilities - true + Compat.Yes } - expectedTy is TyUnit && inferredTy is TyUnit -> true + expectedTy is TyUnit && inferredTy is TyUnit -> Compat.Yes expectedTy is TyInteger && inferredTy is TyInteger -> isCompatibleIntegers(expectedTy, inferredTy) expectedTy is TyPrimitive && inferredTy is TyPrimitive - && expectedTy.name == inferredTy.name -> true + && expectedTy.name == inferredTy.name -> Compat.Yes expectedTy is TyVector && inferredTy is TyVector - && isCompatible(expectedTy.item, inferredTy.item, msl) -> true + && isCompatible(expectedTy.item, inferredTy.item, msl) -> Compat.Yes expectedTy is TyReference && inferredTy is TyReference // inferredTy permissions should be a superset of expectedTy permissions @@ -212,13 +249,14 @@ fun isCompatible(rawExpectedTy: Ty, rawInferredTy: Ty, msl: Boolean = true): Boo expectedTy is TyStruct && inferredTy is TyStruct -> isCompatibleStructs(expectedTy, inferredTy, msl) expectedTy is TyTuple && inferredTy is TyTuple -> isCompatibleTuples(expectedTy, inferredTy, msl) - else -> false + else -> Compat.TypeMismatch(expectedTy, inferredTy) } } sealed class Compat { object Yes : Compat() data class AbilitiesMismatch(val abilities: Set) : Compat() + data class TypeMismatch(val expectedTy: Ty, val ty: Ty) : Compat() } fun isCompatibleAbilities(expectedTy: Ty, actualTy: Ty, msl: Boolean): Compat { @@ -250,11 +288,11 @@ sealed class TypeError(open val element: PsiElement) { data class AbilitiesMismatch( override val element: PsiElement, - val ty: Ty, + val elementTy: Ty, val missingAbilities: Set ) : TypeError(element) { override fun message(): String { - return "The type '${ty.text()}' " + + return "The type '${elementTy.text()}' " + "does not have required ability '${missingAbilities.map { it.label() }.first()}'" } } diff --git a/src/main/kotlin/org/move/lang/core/types/ty/TyFunction.kt b/src/main/kotlin/org/move/lang/core/types/ty/TyFunction.kt index 43bd0dc3c..466d06569 100644 --- a/src/main/kotlin/org/move/lang/core/types/ty/TyFunction.kt +++ b/src/main/kotlin/org/move/lang/core/types/ty/TyFunction.kt @@ -13,8 +13,6 @@ class TyFunction( val acquiresTypes: List, val typeArgs: List, ) : Ty { - var solvable: Boolean = true - override fun innerFoldWith(folder: TypeFolder): Ty { return TyFunction( item, diff --git a/src/main/kotlin/org/move/utils/tests/types/TypificationTestCase.kt b/src/main/kotlin/org/move/utils/tests/types/TypificationTestCase.kt index 4e910b283..8c601933d 100644 --- a/src/main/kotlin/org/move/utils/tests/types/TypificationTestCase.kt +++ b/src/main/kotlin/org/move/utils/tests/types/TypificationTestCase.kt @@ -8,7 +8,7 @@ import org.move.lang.core.psi.MvExpr import org.move.lang.core.psi.MvType import org.move.lang.core.psi.ext.inferredTy import org.move.lang.core.psi.ext.isMsl -import org.move.lang.core.types.infer.functionInferenceCtx +import org.move.lang.core.types.infer.ownerInferenceCtx import org.move.lang.core.types.infer.inferExpectedTy import org.move.utils.tests.InlineFile import org.move.utils.tests.MvTestBase @@ -28,7 +28,7 @@ abstract class TypificationTestCase : MvTestBase() { val (element, data) = myFixture.findElementAndDataInEditor() val expectedType = data.trim() - val ctx = element.functionInferenceCtx(element.isMsl()) + val ctx = element.ownerInferenceCtx(element.isMsl()) val actualType = inferExpectedTy(element, ctx)?.expectedTyText() ?: "null" check(actualType == expectedType) { "Type mismatch. Expected $expectedType, found: $actualType" diff --git a/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt b/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt index 32c67d9ab..9e4cb360a 100644 --- a/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt @@ -5,25 +5,25 @@ import org.move.utils.tests.annotation.InspectionTestBase class MvTypeCheckInspectionTest : InspectionTestBase(MvTypeCheckInspection::class) { fun `test incorrect type address passed where &signer is expected`() = checkErrors( """ - module 0x1::M { - fun send(account: &signer) {} - - fun main(addr: address) { - send(addr); - } - } +module 0x1::M { + fun send(account: &signer) {} + + fun main(addr: address) { + send(addr); + } +} """ ) fun `test incorrect type u8 passed where &signer is expected`() = checkErrors( """ - module 0x1::M { - fun send(account: &signer) {} - - fun main(addr: u8) { - send(addr) - } - } +module 0x1::M { + fun send(account: &signer) {} + + fun main(addr: u8) { + send(addr) + } +} """ ) @@ -57,77 +57,77 @@ class MvTypeCheckInspectionTest : InspectionTestBase(MvTypeCheckInspection::clas fun `test same struct but different generic types`() = checkErrors( """ - module 0x1::M { - struct Option {} - fun is_none(t: Option): bool { - true - } - fun main() { - let opt = Option {}; - is_none(opt); - } - } +module 0x1::M { + struct Option {} + fun is_none(t: Option): bool { + true + } + fun main() { + let opt = Option {}; + is_none(opt); + } +} """ ) fun `test different generic types for references`() = checkErrors( """ - module 0x1::M { - struct Option {} - fun is_none(t: &Option): bool { - true - } - fun main() { - let opt = &Option {}; - is_none(opt); - } - } +module 0x1::M { + struct Option {} + fun is_none(t: &Option): bool { + true + } + fun main() { + let opt = &Option {}; + is_none(opt); + } +} """ ) fun `test immutable reference is not compatible with mutable reference`() = checkErrors( """ - module 0x1::M { - struct Option { - vec: vector - } - fun is_none(t: &mut Option): bool { - true - } - fun main(opt: &Option) { - is_none(opt); - } - } +module 0x1::M { + struct Option { + vec: vector + } + fun is_none(t: &mut Option): bool { + true + } + fun main(opt: &Option) { + is_none(opt); + } +} """ ) fun `test incorrect type of argument with struct literal`() = checkErrors( """ - module 0x1::M { - struct A {} - struct B {} - - fun use_a(a: A) {} - fun main() { - use_a(B {}) - } +module 0x1::M { + struct A {} + struct B {} + + fun use_a(a: A) {} + fun main() { + use_a(B {}) } +} """ ) fun `test incorrect type of argument with call expression`() = checkErrors( """ - module 0x1::M { - struct A {} - struct B {} - - fun use_a(a: A) {} - fun get_b(): B { B {} } - - fun main() { - use_a(get_b()) - } +module 0x1::M { + struct A {} + struct B {} + + fun use_a(a: A) {} + fun get_b(): B { B {} } + + fun main() { + use_a(get_b()) } +} """ ) @@ -144,7 +144,7 @@ module 0x1::M { fun use_a(a: A) {} fun main() { - use_a(get_b()) + use_a(get_b()) } } """ @@ -304,28 +304,28 @@ module 0x1::M { fun `test type check incompatible constraints`() = checkErrors( """ - module 0x1::M { - struct C {} - struct D {} - fun new(a: Content, b: Content): Content { a } - fun m() { - new(C {}, D {}); - } - } +module 0x1::M { + struct C {} + struct D {} + fun new(a: Content, b: Content): Content { a } + fun m() { + new(C {}, D {}); + } +} """ ) fun `test error if resolved type requires a reference`() = checkErrors( """ - module 0x1::M { - fun index_of(v: &vector, e: &Element): (bool, u64) { - (false, 0) - } - fun m() { - let ids: vector; - index_of(&ids, 1u64); - } - } +module 0x1::M { + fun index_of(v: &vector, e: &Element): (bool, u64) { + (false, 0) + } + fun m() { + let ids: vector; + index_of(&ids, 1u64); + } +} """ ) @@ -347,21 +347,21 @@ module 0x1::M { fun `test emit event requires mutable reference error`() = checkErrors( """ - module 0x1::M { - struct EventHandle has store { - counter: u64, - guid: vector, - } - struct Account has key { - handle: EventHandle - } - struct Event has store, drop {} - fun emit_event(handler_ref: &mut EventHandle, msg: T) {} - fun m() acquires Account { - emit_event(borrow_global_mut(@0x1).handle, Event {}); - } - - } +module 0x1::M { + struct EventHandle has store { + counter: u64, + guid: vector, + } + struct Account has key { + handle: EventHandle + } + struct Event has store, drop {} + fun emit_event(handler_ref: &mut EventHandle, msg: T) {} + fun m() acquires Account { + emit_event(borrow_global_mut(@0x1).handle, Event {}); + } + +} """ ) @@ -536,17 +536,6 @@ module 0x1::M { """ ) - fun `test pass generic with abilities when primitive type is expected`() = checkErrors( - """ - module 0x1::M { - fun count(val: u8) {} - fun balance(k: Token) { - count(k); - } - } - """ - ) - fun `test invalid type for field in struct literal`() = checkErrors( """ module 0x1::M { @@ -647,13 +636,13 @@ module 0x1::M { fun `test incorrect type address passed where &signer is expected in spec`() = checkErrors( """ - module 0x1::M { - fun send(account: &signer) {} - - spec send { - send(@0x1) - } - } +module 0x1::M { + fun send(account: &signer) {} + + spec send { + send(@0x1); + } +} """ ) @@ -898,4 +887,53 @@ module 0x1::main { } """ ) + + fun `test vector lit with explicit type and type error`() = checkByText(""" +module 0x1::main { + fun main() { + vector[1u64]; + } +} + """) + + fun `test vector lit with implicit type and type error`() = checkByText(""" +module 0x1::main { + fun main() { + vector[1u8, 1u64]; + } +} + """) + + fun `test call expr with incomplete arguments and explicit type`() = checkByText(""" + module 0x1::main { + fun call(a: T, b: T): T { + b + } + fun main() { + call(1u64); + } + } + """) + + fun `test call expr with incomplete arguments and implicit type`() = checkByText(""" + module 0x1::main { + fun call(a: T, b: T, c: T): T { + b + } + fun main() { + call(1u8, 1u64); + } + } + """) + +// fun `test generic type is not compatible to primitive type`() = checkErrors( +// """ +// module 0x1::M { +// fun count(val: u8) {} +// fun balance(k: Token) { +// count(); +// } +// } +// """ +// ) } diff --git a/src/test/kotlin/org/move/lang/types/ExpressionTypesTest.kt b/src/test/kotlin/org/move/lang/types/ExpressionTypesTest.kt index d77f42c25..90471e3d0 100644 --- a/src/test/kotlin/org/move/lang/types/ExpressionTypesTest.kt +++ b/src/test/kotlin/org/move/lang/types/ExpressionTypesTest.kt @@ -569,4 +569,60 @@ class ExpressionTypesTest: TypificationTestCase() { } } """) + + fun `test vector lit with explicit type and type error`() = testExpr(""" + module 0x1::main { + fun main() { + let vv = vector[1u64]; + vv; + //^ vector + } + } + """) + + fun `test vector lit with implicit type and type error`() = testExpr(""" + module 0x1::main { + fun main() { + let vv = vector[1u8, 1u64]; + vv; + //^ vector + } + } + """) + + fun `test vector lit inside specs`() = testExpr(""" + module 0x1::main { + spec module { + let vv = vector[1]; + vv; + //^ vector + } + } + """) + + fun `test call expr with explicit type and type error`() = testExpr(""" + module 0x1::main { + fun call(a: T, b: T): T { + b + } + fun main() { + let aa = call(1u64, 1u128); + aa; + //^ u8 + } + } + """) + + fun `test call expr with implicit type and type error`() = testExpr(""" + module 0x1::main { + fun call(a: T, b: T): T { + b + } + fun main() { + let aa = call(1u8, 1u128); + aa; + //^ u8 + } + } + """) } From 03eb38cae16cd6e18aa2f2f3a76d27336fc468a0 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Sun, 18 Sep 2022 12:00:57 +0200 Subject: [PATCH 14/26] tests for incompatibilities with aptos --- .../inspections/MvTypeCheckInspectionTest.kt | 42 +++++++++++++---- .../MvUnusedImportInspectionTest.kt | 47 +++++++++++++++++++ .../PhantomTypeParameterInspectionTest.kt | 28 +++++++++++ .../RedundantQualifiedPathInspectionTest.kt | 14 ++++++ 4 files changed, 121 insertions(+), 10 deletions(-) diff --git a/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt b/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt index 9e4cb360a..754666c2e 100644 --- a/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt @@ -926,14 +926,36 @@ module 0x1::main { } """) -// fun `test generic type is not compatible to primitive type`() = checkErrors( -// """ -// module 0x1::M { -// fun count(val: u8) {} -// fun balance(k: Token) { -// count(); -// } -// } -// """ -// ) + fun `test option none is compatible with any option`() = checkByText(""" +module 0x1::option { + struct Option has copy, drop, store { + vec: vector + } + public fun none(): Option { + Option { vec: vector::empty() } + } +} +module 0x1::main { + use 0x1::option; + struct IterableValue has store { + prev: option::Option, + next: option::Option, + } + public fun new() { + IterableValue { prev: option::none(), next: option::none() }; + } +} + """) + + fun `test deeply nested structure type is unknown due to memory issues`() = checkByText(""" +module 0x1::main { + struct Box { x: T } + struct Box3 { x: Box> } +// struct Box7 { x: Box3> } +// struct Box15 { x: Box7> } + fun main() { + let a: Box3; + } +} + """) } diff --git a/src/test/kotlin/org/move/ide/inspections/MvUnusedImportInspectionTest.kt b/src/test/kotlin/org/move/ide/inspections/MvUnusedImportInspectionTest.kt index b35049546..3ffdf7568 100644 --- a/src/test/kotlin/org/move/ide/inspections/MvUnusedImportInspectionTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/MvUnusedImportInspectionTest.kt @@ -357,4 +357,51 @@ module 0x1::main { } } """) + + fun `test no unused import for function return type`() = checkWarnings(""" +module 0x1::string { + struct String {} +} +module 0x1::main { + use 0x1::string; + public fun type_name(): string::String {} +} + """) + + fun `test no unused import for native function return type`() = checkWarnings(""" +module 0x1::string { + struct String {} +} +module 0x1::main { + use 0x1::string; + public native fun type_name(): string::String; +} + """) + + fun `test unused import if imported locally`() = checkWarnings(""" +module 0x1::string { + public fun call() {} +} +module 0x1::main { + use 0x1::string; + fun main() { + use 0x1::string; + string::call(); + } +} + """) + + fun `test unused import if imported locally test_only`() = checkWarnings(""" +module 0x1::string { + public fun call() {} +} +module 0x1::main { + use 0x1::string; + #[test_only] + fun main() { + use 0x1::string; + string::call(); + } +} + """) } diff --git a/src/test/kotlin/org/move/ide/inspections/PhantomTypeParameterInspectionTest.kt b/src/test/kotlin/org/move/ide/inspections/PhantomTypeParameterInspectionTest.kt index c2d5575ef..2fc8e7f1f 100644 --- a/src/test/kotlin/org/move/ide/inspections/PhantomTypeParameterInspectionTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/PhantomTypeParameterInspectionTest.kt @@ -102,4 +102,32 @@ class PhantomTypeParameterInspectionTest : InspectionTestBase(PhantomTypeParamet struct R<T> { val: S> } } """) + + fun `test twice nested non-phantom type`() = checkByText( + """ +module 0x1::main { + struct Value has store { + key: K, + val: V + } + struct Table has store { + inner: vector>, + } +} + """ + ) + + fun `test three times nested non-phantom type`() = checkByText( + """ +module 0x1::main { + struct Value has store { + key: K, + val: V + } + struct Table has store { + inner: vector>>, + } +} + """ + ) } diff --git a/src/test/kotlin/org/move/ide/inspections/RedundantQualifiedPathInspectionTest.kt b/src/test/kotlin/org/move/ide/inspections/RedundantQualifiedPathInspectionTest.kt index 5631936dc..1330c3d5a 100644 --- a/src/test/kotlin/org/move/ide/inspections/RedundantQualifiedPathInspectionTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/RedundantQualifiedPathInspectionTest.kt @@ -209,4 +209,18 @@ class RedundantQualifiedPathInspectionTest : InspectionTestBase(RedundantQualifi """ ) + fun `test no redundant qualifier if import is in a different scope`() = checkByText(""" +module 0x1::string { + public fun call() {} +} +module 0x1::main { + #[test_only] + use 0x1::string; + + fun main() { + 0x1::string::call(); + } +} + """) + } From e79f9479b747a800e332f4221cb9a582213a05cb Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Sun, 18 Sep 2022 12:02:10 +0200 Subject: [PATCH 15/26] add missing binary op --- src/main/kotlin/org/move/lang/core/MoveTokenType.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/move/lang/core/MoveTokenType.kt b/src/main/kotlin/org/move/lang/core/MoveTokenType.kt index 727730551..e6d2dece1 100644 --- a/src/main/kotlin/org/move/lang/core/MoveTokenType.kt +++ b/src/main/kotlin/org/move/lang/core/MoveTokenType.kt @@ -30,9 +30,9 @@ val MOVE_BINARY_OPS = tokenSetOf( OR_OR, AND_AND, EQ_EQ_GT, LT_EQ_EQ_GT, LT, LT_EQ, GT, GT_EQ, - EQ, EQ_EQ, + LT_LT, GT_GT, + EQ_EQ, NOT_EQ, OR, AND, XOR, - EQ, NOT_EQ, MUL, DIV, MODULO, PLUS, MINUS, XOR, AND, OR From add69accf2c3652fbda507293a0b68191bbf7539 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Sun, 18 Sep 2022 16:18:00 +0200 Subject: [PATCH 16/26] caching of type type inference, give up on very deep structs --- .../move/ide/annotator/MvErrorAnnotator.kt | 9 ++-- .../move/ide/docs/MvDocumentationProvider.kt | 8 +-- .../hints/StructLiteralFieldsInfoHandler.kt | 3 +- .../ide/inspections/MvTypeCheckInspection.kt | 6 +-- .../MvUnusedAcquiresTypeInspection.kt | 8 +-- .../inspections/MvUnusedVariableInspection.kt | 5 +- .../PhantomTypeParameterInspection.kt | 3 +- .../lang/core/completion/LookupElements.kt | 2 +- .../lang/core/completion/MvLookupElement.kt | 4 +- .../org/move/lang/core/psi/MvFunctionLike.kt | 32 ++++++----- .../move/lang/core/psi/ext/MoveConstDef.kt | 5 +- .../lang/core/psi/ext/MoveStructFieldDef.kt | 6 ++- .../move/lang/core/psi/ext/MoveStructPat.kt | 3 +- .../move/lang/core/psi/ext/MvAcquiresType.kt | 12 ----- .../move/lang/core/psi/ext/MvBindingPat.kt | 24 ++------- .../org/move/lang/core/psi/ext/MvFunction.kt | 4 +- .../lang/core/psi/ext/MvFunctionParameter.kt | 8 +-- .../move/lang/core/psi/ext/MvLetStatement.kt | 2 - .../org/move/lang/core/psi/ext/MvSchema.kt | 3 +- .../core/psi/ext/MvSchemaFieldStatement.kt | 9 ++-- .../org/move/lang/core/psi/ext/MvStruct.kt | 4 +- .../org/move/lang/core/psi/ext/MvType.kt | 4 +- .../lang/core/types/infer/ExpectedType.kt | 12 ++--- .../move/lang/core/types/infer/Expressions.kt | 18 +++---- .../org/move/lang/core/types/infer/Fold.kt | 53 +++++++++++-------- .../lang/core/types/infer/InferenceContext.kt | 26 ++++++--- .../lang/core/types/infer/TypeDeclarations.kt | 38 +++++++------ .../org/move/lang/core/types/ty/TyFunction.kt | 2 +- .../org/move/lang/core/types/ty/TyStruct.kt | 5 +- .../org/move/lang/core/types/ty/TyVector.kt | 6 ++- .../kotlin/org/move/stdext/Collections.kt | 2 +- .../ide/docs/MoveDocumentationProviderTest.kt | 16 ++++++ .../inspections/MvTypeCheckInspectionTest.kt | 35 ++++++++++-- 33 files changed, 211 insertions(+), 166 deletions(-) delete mode 100644 src/main/kotlin/org/move/lang/core/psi/ext/MvAcquiresType.kt diff --git a/src/main/kotlin/org/move/ide/annotator/MvErrorAnnotator.kt b/src/main/kotlin/org/move/ide/annotator/MvErrorAnnotator.kt index 9dfdffefc..58d612042 100644 --- a/src/main/kotlin/org/move/ide/annotator/MvErrorAnnotator.kt +++ b/src/main/kotlin/org/move/ide/annotator/MvErrorAnnotator.kt @@ -8,6 +8,8 @@ import org.move.ide.presentation.fullname import org.move.lang.MvElementTypes.R_PAREN import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.* +import org.move.lang.core.types.infer.InferenceContext +import org.move.lang.core.types.infer.inferTypeTy import org.move.lang.core.types.ty.TyUnknown import org.move.lang.modules import org.move.lang.moveProject @@ -110,10 +112,11 @@ class MvErrorAnnotator : MvAnnotator() { if (o.path.referenceName in GLOBAL_STORAGE_ACCESS_FUNCTIONS) { val explicitTypeArgs = o.typeArguments val currentModule = o.containingModule ?: return + val inferenceCtx = InferenceContext(o.isMsl()) for (typeArg in explicitTypeArgs) { - val ty = typeArg.type.ty() - if (ty !is TyUnknown && !ty.canBeAcquiredInModule(currentModule)) { - val typeName = ty.fullname() + val typeArgTy = inferTypeTy(typeArg.type, inferenceCtx) + if (typeArgTy !is TyUnknown && !typeArgTy.canBeAcquiredInModule(currentModule)) { + val typeName = typeArgTy.fullname() holder.newAnnotation( HighlightSeverity.ERROR, "The type '$typeName' was not declared in the current module. " + diff --git a/src/main/kotlin/org/move/ide/docs/MvDocumentationProvider.kt b/src/main/kotlin/org/move/ide/docs/MvDocumentationProvider.kt index e21ecbb2b..e53e3b1e2 100644 --- a/src/main/kotlin/org/move/ide/docs/MvDocumentationProvider.kt +++ b/src/main/kotlin/org/move/ide/docs/MvDocumentationProvider.kt @@ -10,6 +10,8 @@ import org.move.ide.presentation.text import org.move.ide.presentation.typeLabel import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.* +import org.move.lang.core.types.infer.InferenceContext +import org.move.lang.core.types.infer.inferTypeTy import org.move.lang.core.types.infer.ownerInferenceCtx import org.move.lang.core.types.ty.Ty import org.move.lang.moveProject @@ -128,7 +130,7 @@ fun MvElement.signature(builder: StringBuilder) { buffer += this.struct.name ?: angleWrapped("anonymous") buffer += "\n" buffer.b { it += this.name } - buffer += ": ${this.declarationTy(false).renderForDocs(true)}" + buffer += ": ${this.declarationTypeTy(InferenceContext(false)).renderForDocs(true)}" } is MvConst -> { @@ -136,7 +138,7 @@ fun MvElement.signature(builder: StringBuilder) { buffer += "\n" buffer += "const " buffer.b { it += this.bindingPat?.name ?: angleWrapped("unknown") } - buffer += ": ${this.declaredTy(false).renderForDocs(false)}" + buffer += ": ${this.declarationTy(InferenceContext(false)).renderForDocs(false)}" this.initializer?.let { buffer += " ${it.text}" } } @@ -153,7 +155,7 @@ private fun PsiElement.generateDocumentation( buffer += prefix when (this) { is MvType -> { - buffer += this.ty().typeLabel(this) + buffer += inferTypeTy(this, InferenceContext(this.isMsl())).typeLabel(this) } is MvFunctionParameterList -> diff --git a/src/main/kotlin/org/move/ide/hints/StructLiteralFieldsInfoHandler.kt b/src/main/kotlin/org/move/ide/hints/StructLiteralFieldsInfoHandler.kt index ed62243ff..7579bd2b1 100644 --- a/src/main/kotlin/org/move/ide/hints/StructLiteralFieldsInfoHandler.kt +++ b/src/main/kotlin/org/move/ide/hints/StructLiteralFieldsInfoHandler.kt @@ -12,6 +12,7 @@ import org.move.lang.core.psi.MvStructLitField import org.move.lang.core.psi.MvStructLitFieldsBlock import org.move.lang.core.psi.MvValueArgumentList import org.move.lang.core.psi.ext.* +import org.move.lang.core.types.infer.InferenceContext import org.move.utils.AsyncParameterInfoHandler class StructLitFieldsInfoHandler : @@ -100,7 +101,7 @@ class FieldsDescription(val fields: Array) { val struct = block.litExpr.path.maybeStruct ?: return null val fieldParams = struct.fieldsMap.entries.map { (name, field) -> - val type = field.declarationTy(false).fullname() + val type = field.declarationTypeTy(InferenceContext(false)).fullname() "$name: $type" }.toTypedArray() return FieldsDescription(fieldParams) diff --git a/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt b/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt index 07b75050a..2b5ba620f 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvTypeCheckInspection.kt @@ -7,7 +7,7 @@ import com.intellij.psi.PsiElement import org.move.ide.presentation.name import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.* -import org.move.lang.core.types.infer.MvInferenceContextOwner +import org.move.lang.core.types.infer.InferenceContext import org.move.lang.core.types.infer.TypeError import org.move.lang.core.types.infer.inferenceCtx import org.move.lang.core.types.infer.isCompatible @@ -45,11 +45,11 @@ class MvTypeCheckInspection : MvLocalInspectionTool() { } override fun visitStructField(field: MvStructField) { - val msl = field.isMsl() +// val msl = field.isMsl() val structAbilities = field.struct.tyAbilities if (structAbilities.isEmpty()) return - val fieldTy = field.declarationTy(msl) as? TyStruct ?: return + val fieldTy = field.declarationTypeTy(InferenceContext(false)) as? TyStruct ?: return for (ability in structAbilities) { val requiredAbility = ability.requires() if (requiredAbility !in fieldTy.abilities()) { diff --git a/src/main/kotlin/org/move/ide/inspections/MvUnusedAcquiresTypeInspection.kt b/src/main/kotlin/org/move/ide/inspections/MvUnusedAcquiresTypeInspection.kt index 4df94cd3d..17e3c252f 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvUnusedAcquiresTypeInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvUnusedAcquiresTypeInspection.kt @@ -11,7 +11,7 @@ import org.move.ide.presentation.fullnameNoArgs import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.acquiresTys import org.move.lang.core.psi.ext.isMsl -import org.move.lang.core.psi.ext.ty +import org.move.lang.core.types.infer.inferTypeTy import org.move.lang.core.types.infer.inferenceCtx @@ -46,10 +46,10 @@ class MvUnusedAcquiresTypeInspection : MvLocalInspectionTool() { val function = o.parent as? MvFunction ?: return val module = function.module ?: return val codeBlock = function.codeBlock ?: return - val ctx = function.inferenceCtx(codeBlock.isMsl()) + val inferenceCtx = function.inferenceCtx(codeBlock.isMsl()) val blockAcquiredTys = codeBlock .descendantsOfType() - .flatMap { it.acquiresTys(ctx) } + .flatMap { it.acquiresTys(inferenceCtx) } .map { it.fullnameNoArgs() } .toSet() @@ -58,7 +58,7 @@ class MvUnusedAcquiresTypeInspection : MvLocalInspectionTool() { val pathTypes = o.pathTypeList for ((i, pathType) in pathTypes.withIndex()) { // check that this acquires is allowed in the context - val ty = pathType.ty() + val ty = inferTypeTy(pathType, inferenceCtx) if (!ty.canBeAcquiredInModule(module)) { unusedAcquiresIndices.add(i) continue diff --git a/src/main/kotlin/org/move/ide/inspections/MvUnusedVariableInspection.kt b/src/main/kotlin/org/move/ide/inspections/MvUnusedVariableInspection.kt index 3dae09484..8953233ea 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvUnusedVariableInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvUnusedVariableInspection.kt @@ -1,16 +1,13 @@ package org.move.ide.inspections -import com.intellij.codeInspection.LocalQuickFix -import com.intellij.codeInspection.ProblemDescriptor import com.intellij.codeInspection.ProblemHighlightType import com.intellij.codeInspection.ProblemsHolder -import com.intellij.openapi.project.Project import com.intellij.psi.util.descendantsOfType import org.move.ide.inspections.fixes.RemoveParameterFix import org.move.ide.inspections.fixes.RenameFix import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.owner -import org.move.lang.core.psi.mixins.functionLike +import org.move.lang.core.psi.ext.functionLike class MvUnusedVariableInspection : MvLocalInspectionTool() { override fun buildMvVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) = diff --git a/src/main/kotlin/org/move/ide/inspections/PhantomTypeParameterInspection.kt b/src/main/kotlin/org/move/ide/inspections/PhantomTypeParameterInspection.kt index 058401748..9f2c6eb65 100644 --- a/src/main/kotlin/org/move/ide/inspections/PhantomTypeParameterInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/PhantomTypeParameterInspection.kt @@ -5,6 +5,7 @@ import com.intellij.psi.util.descendantsOfType import org.move.ide.inspections.fixes.PhantomFix import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.* +import org.move.lang.core.types.infer.InferenceContext import org.move.lang.core.types.infer.visitTyTypeParameterWith class PhantomTypeParameterInspection : MvLocalInspectionTool() { @@ -17,7 +18,7 @@ class PhantomTypeParameterInspection : MvLocalInspectionTool() { val fieldUsedTypeParams = mutableListOf() // find all MvTypeParameter used in field declaration - structField.declarationTy(false) + structField.declarationTypeTy(InferenceContext(false)) .visitTyTypeParameterWith { fieldUsedTypeParams.add(it.origin) } // find all MvTypeArgument, check their phantom status diff --git a/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt b/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt index ddfd80f9d..bdbece1cd 100644 --- a/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt +++ b/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt @@ -207,7 +207,7 @@ open class DefaultInsertHandler(val completionContext: CompletionContext? = null if (completionContext == null) return@run false val msl = element.isMsl() val inferenceCtx = InferenceContext(msl) - val funcTy = instantiateItemTy(element, msl) as? TyFunction ?: return@run false + val funcTy = instantiateItemTy(element, inferenceCtx) as? TyFunction ?: return@run false val expectedTy = completionContext.expectedTy if (expectedTy != null) { diff --git a/src/main/kotlin/org/move/lang/core/completion/MvLookupElement.kt b/src/main/kotlin/org/move/lang/core/completion/MvLookupElement.kt index eb5d0b217..41b75ea4d 100644 --- a/src/main/kotlin/org/move/lang/core/completion/MvLookupElement.kt +++ b/src/main/kotlin/org/move/lang/core/completion/MvLookupElement.kt @@ -74,8 +74,8 @@ fun lookupProperties(element: MvNamedElement, context: CompletionContext): Looku private fun MvNamedElement.asTy(ctx: InferenceContext): Ty = when (this) { // is RsFieldDecl -> typeReference?.type - is MvFunction -> this.returnTy - is MvStruct -> instantiateItemTy(this, ctx.msl) + is MvFunction -> this.returnTypeTy(ctx) + is MvStruct -> instantiateItemTy(this, ctx) is MvBindingPat -> this.inferredTy(ctx) else -> TyUnknown } diff --git a/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt b/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt index a06e2de9e..7ee47c9b0 100644 --- a/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt +++ b/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt @@ -1,17 +1,15 @@ package org.move.lang.core.psi import org.move.lang.MvElementTypes -import org.move.lang.core.psi.ext.MvDocAndAttributeOwner -import org.move.lang.core.psi.ext.hasChild -import org.move.lang.core.psi.ext.ty -import org.move.lang.core.psi.mixins.declaredTy +import org.move.lang.core.psi.ext.* +import org.move.lang.core.types.infer.InferenceContext import org.move.lang.core.types.infer.MvInferenceContextOwner import org.move.lang.core.types.infer.foldTyTypeParameterWith +import org.move.lang.core.types.infer.inferTypeTy import org.move.lang.core.types.ty.Ty import org.move.lang.core.types.ty.TyUnit import org.move.lang.core.types.ty.TyUnknown -import org.move.stdext.chain -import org.move.stdext.wrapWithList +import org.move.stdext.withAdded interface MvFunctionLike : MvTypeParametersOwner, MvNameIdentifierOwner, @@ -30,21 +28,20 @@ val MvFunctionLike.isNative get() = hasChild(MvElementTypes.NATIVE) val MvFunctionLike.parameters get() = this.functionParameterList?.functionParameterList.orEmpty() -val MvFunctionLike.returnTy: Ty - get() { - val returnTypeElement = this.returnType - return if (returnTypeElement == null) { - TyUnit - } else { - returnTypeElement.type?.ty() ?: TyUnknown - } +fun MvFunctionLike.returnTypeTy(inferenceCtx: InferenceContext): Ty { + val returnTypeElement = this.returnType + return if (returnTypeElement == null) { + TyUnit + } else { + returnTypeElement.type?.let { inferTypeTy(it, inferenceCtx) } ?: TyUnknown } +} val MvFunctionLike.typeParamsUsedOnlyInReturnType: List get() { val usedTypeParams = mutableSetOf() this.parameters - .map { it.declaredTy(false) } + .map { it.declarationTypeTy(InferenceContext(false)) } .forEach { it.foldTyTypeParameterWith { paramTy -> usedTypeParams.add(paramTy.origin); paramTy } } @@ -54,9 +51,10 @@ val MvFunctionLike.typeParamsUsedOnlyInReturnType: List val MvFunctionLike.requiredTypeParams: List get() { val usedTypeParams = mutableSetOf() + val inferenceCtx = InferenceContext(false) this.parameters - .map { it.declaredTy(false) } - .chain(this.returnType?.type?.ty().wrapWithList()) + .map { it.declarationTypeTy(inferenceCtx) } + .withAdded(this.returnTypeTy(inferenceCtx)) .forEach { it.foldTyTypeParameterWith { paramTy -> usedTypeParams.add(paramTy.origin); paramTy } } diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MoveConstDef.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MoveConstDef.kt index a7900ba99..2a97d8a65 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MoveConstDef.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MoveConstDef.kt @@ -1,9 +1,10 @@ package org.move.lang.core.psi.ext import org.move.lang.core.psi.MvConst +import org.move.lang.core.types.infer.InferenceContext import org.move.lang.core.types.infer.inferTypeTy import org.move.lang.core.types.ty.Ty import org.move.lang.core.types.ty.TyUnknown -fun MvConst.declaredTy(msl: Boolean): Ty = - this.typeAnnotation?.type?.let { inferTypeTy(it, msl) } ?: TyUnknown +fun MvConst.declarationTy(inferenceCtx: InferenceContext): Ty = + this.typeAnnotation?.type?.let { inferTypeTy(it, inferenceCtx) } ?: TyUnknown diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MoveStructFieldDef.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MoveStructFieldDef.kt index c4d601c0c..a9b1fbcad 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MoveStructFieldDef.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MoveStructFieldDef.kt @@ -3,6 +3,7 @@ package org.move.lang.core.psi.ext import org.move.lang.core.psi.MvStruct import org.move.lang.core.psi.MvStructBlock import org.move.lang.core.psi.MvStructField +import org.move.lang.core.types.infer.InferenceContext import org.move.lang.core.types.infer.inferTypeTy import org.move.lang.core.types.ty.Ty import org.move.lang.core.types.ty.TyUnknown @@ -15,5 +16,6 @@ val MvStructField.struct: MvStruct get() = fieldsDefBlock?.parent as MvStruct -fun MvStructField.declarationTy(msl: Boolean): Ty = - this.typeAnnotation?.type?.let { inferTypeTy(it, msl) } ?: TyUnknown +fun MvStructField.declarationTypeTy(inferenceCtx: InferenceContext): Ty = + this.typeAnnotation?.type + ?.let { inferTypeTy(it, inferenceCtx) } ?: TyUnknown diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MoveStructPat.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MoveStructPat.kt index ea3423270..42a8a064e 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MoveStructPat.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MoveStructPat.kt @@ -4,6 +4,7 @@ import org.move.lang.core.psi.MvStruct import org.move.lang.core.psi.MvStructPat import org.move.lang.core.psi.MvStructPatField import org.move.lang.core.psi.typeParameters +import org.move.lang.core.types.infer.InferenceContext import org.move.lang.core.types.infer.instantiateItemTy import org.move.lang.core.types.ty.Ty import org.move.lang.core.types.ty.TyUnknown @@ -20,5 +21,5 @@ fun MvStructPat.ty(): Ty { val struct = this.path.reference?.resolve() as? MvStruct ?: return TyUnknown // TODO: if one or more type arguments if (struct.typeParameters.isNotEmpty()) return TyUnknown - return instantiateItemTy(struct, this.isMsl()) + return instantiateItemTy(struct, InferenceContext(this.isMsl())) } diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvAcquiresType.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvAcquiresType.kt deleted file mode 100644 index 871165a4f..000000000 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvAcquiresType.kt +++ /dev/null @@ -1,12 +0,0 @@ -package org.move.lang.core.psi.ext - -import org.move.lang.core.psi.MvAcquiresType -import org.move.lang.core.types.ty.TyStruct - -val MvAcquiresType.typeFQNames: List? - get() { - return pathTypeList - .map { it.ty() } - .map { (it as? TyStruct) ?: return null } - .map { it.item.fqName } - } diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvBindingPat.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvBindingPat.kt index b32af6bfc..2e49f8c4e 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvBindingPat.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvBindingPat.kt @@ -8,7 +8,6 @@ import com.intellij.psi.util.PsiTreeUtil import org.move.ide.MoveIcons import org.move.lang.core.psi.* import org.move.lang.core.psi.impl.MvNameIdentifierOwnerImpl -import org.move.lang.core.psi.mixins.declaredTy import org.move.lang.core.types.infer.InferenceContext import org.move.lang.core.types.infer.collectBindings import org.move.lang.core.types.infer.inferExprTy @@ -25,21 +24,6 @@ val MvBindingPat.owner: PsiElement? || it is MvSchemaFieldStmt } -fun MvBindingPat.declaredTy(parentCtx: InferenceContext): Ty? { - val owner = this.owner - return when (owner) { - is MvFunctionParameter -> owner.declaredTy(parentCtx.msl) - is MvConst -> owner.declaredTy(parentCtx.msl) - is MvSchemaFieldStmt -> owner.declaredTy(parentCtx.msl) - is MvLetStmt -> { - val explicitType = owner.typeAnnotation?.type ?: return null - val typeTy = inferTypeTy(explicitType, parentCtx.msl) - parentCtx.resolveTy(typeTy) - } - else -> TyUnknown - } -} - fun MvBindingPat.inferredTy(parentCtx: InferenceContext): Ty { val existingTy = parentCtx.bindingTypes[this] if (existingTy != null) { @@ -47,15 +31,15 @@ fun MvBindingPat.inferredTy(parentCtx: InferenceContext): Ty { } val owner = this.owner return when (owner) { - is MvFunctionParameter -> owner.declaredTy(parentCtx.msl) - is MvConst -> owner.declaredTy(parentCtx.msl) + is MvFunctionParameter -> owner.declarationTypeTy(parentCtx) + is MvConst -> owner.declarationTy(parentCtx) is MvLetStmt -> { if (parentCtx.bindingTypes.containsKey(this)) return parentCtx.bindingTypes[this]!! val pat = owner.pat ?: return TyUnknown val explicitType = owner.typeAnnotation?.type if (explicitType != null) { - val explicitTy = inferTypeTy(explicitType, parentCtx.msl) + val explicitTy = inferTypeTy(explicitType, parentCtx) collectBindings(pat, explicitTy, parentCtx) return parentCtx.bindingTypes[this] ?: TyUnknown } @@ -63,7 +47,7 @@ fun MvBindingPat.inferredTy(parentCtx: InferenceContext): Ty { collectBindings(pat, inferredTy, parentCtx) return parentCtx.bindingTypes[this] ?: TyUnknown } - is MvSchemaFieldStmt -> owner.declaredTy(parentCtx.msl) + is MvSchemaFieldStmt -> owner.declarationTypeTy(parentCtx) else -> TyUnknown } } diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvFunction.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvFunction.kt index aa011fd6b..8ce53bd30 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvFunction.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvFunction.kt @@ -4,7 +4,6 @@ import com.intellij.ide.projectView.PresentationData import com.intellij.lang.ASTNode import com.intellij.navigation.ItemPresentation import com.intellij.openapi.editor.colors.TextAttributesKey -import com.intellij.psi.PsiReference import com.intellij.psi.util.CachedValuesManager.getProjectPsiDependentCache import com.intellij.util.PlatformIcons import org.move.ide.MoveIcons @@ -14,6 +13,7 @@ import org.move.lang.core.psi.MvFunction import org.move.lang.core.psi.MvItemSpec import org.move.lang.core.psi.impl.MvNameIdentifierOwnerImpl import org.move.lang.core.psi.module +import org.move.lang.core.types.infer.InferenceContext import org.move.lang.core.types.ty.Ty import javax.swing.Icon @@ -44,7 +44,7 @@ val MvFunction.isTest: Boolean val MvFunction.acquiresTys: List get() = - this.acquiresType?.pathTypeList.orEmpty().map { it.ty() } + this.acquiresType?.pathTypeList.orEmpty().map { it.typeTy(InferenceContext(true)) } val MvFunction.signatureText: String get() { diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvFunctionParameter.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvFunctionParameter.kt index 905acb602..6642c48b5 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvFunctionParameter.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvFunctionParameter.kt @@ -1,12 +1,14 @@ -package org.move.lang.core.psi.mixins +package org.move.lang.core.psi.ext import org.move.lang.core.psi.MvFunctionLike import org.move.lang.core.psi.MvFunctionParameter +import org.move.lang.core.types.infer.InferenceContext import org.move.lang.core.types.infer.inferTypeTy import org.move.lang.core.types.ty.Ty import org.move.lang.core.types.ty.TyUnknown -fun MvFunctionParameter.declaredTy(msl: Boolean): Ty = - this.typeAnnotation?.type?.let { inferTypeTy(it, msl) } ?: TyUnknown +fun MvFunctionParameter.declarationTypeTy(inferenceCtx: InferenceContext): Ty = + this.typeAnnotation?.type + ?.let { inferTypeTy(it, inferenceCtx) } ?: TyUnknown val MvFunctionParameter.functionLike get() = this.parent.parent as? MvFunctionLike diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvLetStatement.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvLetStatement.kt index edce1e699..8ca77db7b 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvLetStatement.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvLetStatement.kt @@ -5,5 +5,3 @@ import org.move.lang.core.psi.MvLetStmt import org.move.lang.core.types.ty.Ty val MvLetStmt.isPost: Boolean get() = this.hasChild(POST) - -val MvLetStmt.declaredTy: Ty? get() = this.typeAnnotation?.type?.ty() diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvSchema.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvSchema.kt index fdb843a61..ad12c0c6f 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvSchema.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvSchema.kt @@ -1,6 +1,7 @@ package org.move.lang.core.psi.ext import org.move.lang.core.psi.* +import org.move.lang.core.types.infer.InferenceContext import org.move.lang.core.types.infer.foldTyTypeParameterWith val MvSchema.specBlock: MvItemSpecBlock? get() = this.childOfType() @@ -17,7 +18,7 @@ val MvSchema.requiredTypeParams: List get() { val usedTypeParams = mutableSetOf() this.fieldStmts - .map { it.declaredTy(true) } + .map { it.declarationTypeTy(InferenceContext(true)) } .forEach { it.foldTyTypeParameterWith { paramTy -> usedTypeParams.add(paramTy.origin); paramTy } } diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvSchemaFieldStatement.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvSchemaFieldStatement.kt index c203ee6d4..65501e72d 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvSchemaFieldStatement.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvSchemaFieldStatement.kt @@ -1,12 +1,11 @@ package org.move.lang.core.psi.ext import org.move.lang.core.psi.MvSchemaFieldStmt +import org.move.lang.core.types.infer.InferenceContext import org.move.lang.core.types.infer.inferTypeTy import org.move.lang.core.types.ty.Ty import org.move.lang.core.types.ty.TyUnknown -//abstract class MvSchemaFieldStmtMixin(node: ASTNode) : MvNameIdentifierOwnerImpl(node), -// MvSchemaFieldStmt - -fun MvSchemaFieldStmt.declaredTy(msl: Boolean): Ty = - this.typeAnnotation.type?.let { inferTypeTy(it, msl) } ?: TyUnknown +fun MvSchemaFieldStmt.declarationTypeTy(inferenceCtx: InferenceContext): Ty = + this.typeAnnotation.type + ?.let { inferTypeTy(it, inferenceCtx) } ?: TyUnknown diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvStruct.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvStruct.kt index 7cc1e7cbc..ae1d4a3c1 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvStruct.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvStruct.kt @@ -7,7 +7,7 @@ import org.move.lang.MvElementTypes import org.move.lang.core.psi.* import org.move.lang.core.psi.impl.MvNameIdentifierOwnerImpl import org.move.lang.core.types.ty.Ability -import org.move.stdext.withElement +import org.move.stdext.withAdded import javax.swing.Icon val MvStruct.fields: List @@ -50,7 +50,7 @@ val MvStruct.hasPhantomTypeParameters get() = this.typeParameters.any { it.isPha fun MvStruct.addAbility(ability: String) { if (ability in this.abilities.map { it.text }) return - val newAbilities = this.abilities.mapNotNull { it.text }.withElement(ability) + val newAbilities = this.abilities.mapNotNull { it.text }.withAdded(ability) val newAbilitiesList = project.psiFactory.abilitiesList(newAbilities) if (this.abilitiesList != null) { this.abilitiesList?.replace(newAbilitiesList) diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvType.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvType.kt index 974b012f6..7c3bbe5e0 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvType.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvType.kt @@ -1,15 +1,15 @@ package org.move.lang.core.psi.ext -import com.intellij.psi.util.CachedValuesManager.getProjectPsiDependentCache import org.move.lang.core.psi.MvPathType import org.move.lang.core.psi.MvRefType import org.move.lang.core.psi.MvType import org.move.lang.core.psi.MvTypeArgument import org.move.lang.core.resolve.ref.MvReference +import org.move.lang.core.types.infer.InferenceContext import org.move.lang.core.types.infer.inferTypeTy import org.move.lang.core.types.ty.Ty -fun MvType.ty(): Ty = getProjectPsiDependentCache(this) { inferTypeTy(it, it.isMsl()) } +fun MvType.typeTy(inferenceCtx: InferenceContext): Ty = inferTypeTy(this, inferenceCtx) val MvType.moveReference: MvReference? get() = when (this) { diff --git a/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt b/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt index 3f58124f5..d11ca3fac 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/ExpectedType.kt @@ -8,11 +8,11 @@ import org.move.lang.core.types.ty.Ty import org.move.lang.core.types.ty.TyReference import org.move.lang.core.types.ty.TyStruct -fun inferExpectedTy(element: PsiElement, ctx: InferenceContext): Ty? { +fun inferExpectedTy(element: PsiElement, parentCtx: InferenceContext): Ty? { val owner = element.parent return when (owner) { is MvBorrowExpr -> { - val refTy = inferExpectedTy(owner, ctx) as? TyReference ?: return null + val refTy = inferExpectedTy(owner, parentCtx) as? TyReference ?: return null refTy.innerTy() } is MvTypeArgument -> { @@ -54,9 +54,9 @@ fun inferExpectedTy(element: PsiElement, ctx: InferenceContext): Ty? { val initializerParent = owner.parent when (initializerParent) { is MvLetStmt -> { - val patExplicitTy = initializerParent.typeAnnotation?.type?.let { inferTypeTy(it, ctx.msl) } + val patExplicitTy = initializerParent.typeAnnotation?.type?.let { inferTypeTy(it, parentCtx) } initializerParent.pat - ?.let { inferPatTy(it, ctx, patExplicitTy) } + ?.let { inferPatTy(it, parentCtx, patExplicitTy) } } else -> null } @@ -64,8 +64,8 @@ fun inferExpectedTy(element: PsiElement, ctx: InferenceContext): Ty? { is MvStructLitField -> { // only first level field for now, rewrite later as recursive val structLitExpr = owner.structLitExpr - val structExpectedTy = inferExpectedTy(structLitExpr, ctx) - val structTy = inferExprTy(structLitExpr, ctx, structExpectedTy) as? TyStruct ?: return null + val structExpectedTy = inferExpectedTy(structLitExpr, parentCtx) + val structTy = inferExprTy(structLitExpr, parentCtx, structExpectedTy) as? TyStruct ?: return null structTy.fieldTy(owner.referenceName) } else -> null diff --git a/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt b/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt index cdd2260e8..409d04c3b 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt @@ -29,7 +29,7 @@ fun inferExprTy(expr: MvExpr, parentCtx: InferenceContext, expectedTy: Ty? = nul is MvMoveExpr -> expr.expr?.let { inferExprTy(it, parentCtx) } ?: TyUnknown is MvCopyExpr -> expr.expr?.let { inferExprTy(it, parentCtx) } ?: TyUnknown - is MvCastExpr -> inferTypeTy(expr.type, parentCtx.msl) + is MvCastExpr -> inferTypeTy(expr.type, parentCtx) is MvParensExpr -> expr.expr?.let { inferExprTy(it, parentCtx) } ?: TyUnknown is MvBinaryExpr -> inferBinaryExprTy(expr, parentCtx) @@ -38,7 +38,7 @@ fun inferExprTy(expr: MvExpr, parentCtx: InferenceContext, expectedTy: Ty? = nul is MvIfExpr -> inferIfExprTy(expr, parentCtx, expectedTy) is MvWhileExpr -> inferWhileExprTy(expr, parentCtx) is MvReturnExpr -> { - val fnReturnTy = expr.containingFunction?.returnTy + val fnReturnTy = expr.containingFunction?.returnTypeTy(parentCtx) expr.expr?.let { inferExprTy(it, parentCtx, fnReturnTy) } TyNever } @@ -101,13 +101,13 @@ fun inferCallExprTy( val path = callExpr.path val funcItem = path.reference?.resolve() as? MvFunctionLike ?: return TyUnknown - var funcTy = instantiateItemTy(funcItem, parentCtx.msl) as? TyFunction ?: return TyUnknown + var funcTy = instantiateItemTy(funcItem, parentCtx) as? TyFunction ?: return TyUnknown val inferenceCtx = InferenceContext(parentCtx.msl) // find all types passed as explicit type parameters, create constraints with those if (path.typeArguments.isNotEmpty()) { if (path.typeArguments.size != funcTy.typeVars.size) return TyUnknown for ((typeVar, typeArg) in funcTy.typeVars.zip(path.typeArguments)) { - val typeArgTy = inferTypeTy(typeArg.type, parentCtx.msl) + val typeArgTy = inferTypeTy(typeArg.type, parentCtx) // check compat for abilities val compat = isCompatibleAbilities(typeVar, typeArgTy, path.isMsl()) @@ -175,14 +175,14 @@ fun inferStructLitExpr( ): Ty { val path = litExpr.path val structItem = path.maybeStruct ?: return TyUnknown - val structTy = instantiateItemTy(structItem, parentCtx.msl) as? TyStruct ?: return TyUnknown + val structTy = instantiateItemTy(structItem, parentCtx) as? TyStruct ?: return TyUnknown val inferenceCtx = InferenceContext(parentCtx.msl) // find all types passed as explicit type parameters, create constraints with those if (path.typeArguments.isNotEmpty()) { if (path.typeArguments.size != structTy.typeVars.size) return TyUnknown for ((typeVar, typeArg) in structTy.typeVars.zip(path.typeArguments)) { - val typeArgTy = inferTypeTy(typeArg.type, parentCtx.msl) + val typeArgTy = inferTypeTy(typeArg.type, parentCtx) // check compat for abilities val compat = isCompatibleAbilities(typeVar, typeArgTy, path.isMsl()) @@ -220,14 +220,14 @@ fun inferStructLitExpr( fun inferStructPatTy(structPat: MvStructPat, parentCtx: InferenceContext, expectedTy: Ty?): Ty { val path = structPat.path val struct = structPat.struct ?: return TyUnknown - val structTy = instantiateItemTy(struct, parentCtx.msl) as TyStruct + val structTy = instantiateItemTy(struct, parentCtx) as TyStruct val inferenceCtx = InferenceContext(parentCtx.msl) // find all types passed as explicit type parameters, create constraints with those if (path.typeArguments.isNotEmpty()) { if (path.typeArguments.size != structTy.typeVars.size) return TyUnknown for ((typeVar, typeArg) in structTy.typeVars.zip(path.typeArguments)) { - val typeArgTy = inferTypeTy(typeArg.type, parentCtx.msl) + val typeArgTy = inferTypeTy(typeArg.type, parentCtx) // check compat for abilities val compat = isCompatibleAbilities(typeVar, typeArgTy, path.isMsl()) @@ -265,7 +265,7 @@ fun inferVectorLitExpr(litExpr: MvVectorLitExpr, parentCtx: InferenceContext): T val inferenceCtx = InferenceContext(litExpr.isMsl()) val typeArgument = litExpr.typeArgument if (typeArgument != null) { - val ty = inferTypeTy(typeArgument.type, litExpr.isMsl()) + val ty = inferTypeTy(typeArgument.type, parentCtx) inferenceCtx.addConstraint(tyVector.item, ty) } val exprs = litExpr.vectorLitItems.exprList diff --git a/src/main/kotlin/org/move/lang/core/types/infer/Fold.kt b/src/main/kotlin/org/move/lang/core/types/infer/Fold.kt index 01843d56c..b5ac3ee5f 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/Fold.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/Fold.kt @@ -5,12 +5,33 @@ package org.move.lang.core.types.infer -import org.move.lang.core.types.ty.Substitution import org.move.lang.core.types.ty.Ty import org.move.lang.core.types.ty.TyInfer import org.move.lang.core.types.ty.TyTypeParameter +import org.move.lang.core.types.ty.TyUnknown -typealias TypeFolder = (Ty) -> Ty +abstract class TypeFolder { + val cache = mutableMapOf() + var depth = 0; + + operator fun invoke(ty: Ty): Ty { + // workaround for massively deep structs + if (depth > 25) return TyUnknown + + val cachedTy = cache[ty] + if (cachedTy != null) { + return cachedTy + } else { + val foldedTy = fold(ty) + cache[ty] = foldedTy + return foldedTy + } + } + + abstract fun fold(ty: Ty): Ty +} + +//typealias TypeFolder = (Ty) -> Ty typealias TypeVisitor = (Ty) -> Boolean /** @@ -60,15 +81,17 @@ interface TypeFoldable { /** Deeply replace any [TyInfer] with the function [folder] */ fun TypeFoldable.foldTyInferWith(folder: (TyInfer) -> Ty): T = - foldWith(object : TypeFolder { - override fun invoke(ty: Ty): Ty = - (if (ty is TyInfer) folder(ty) else ty).innerFoldWith(this) + foldWith(object : TypeFolder() { + override fun fold(ty: Ty): Ty { + val foldedTy = if (ty is TyInfer) folder(ty) else ty + return foldedTy.innerFoldWith(this) + } }) /** Deeply replace any [TyTypeParameter] with the function [folder] */ fun TypeFoldable.foldTyTypeParameterWith(folder: (TyTypeParameter) -> Ty): T = - foldWith(object : TypeFolder { - override fun invoke(ty: Ty): Ty = + foldWith(object : TypeFolder() { + override fun fold(ty: Ty): Ty = if (ty is TyTypeParameter) folder(ty) else ty.innerFoldWith(this) }) // @@ -78,22 +101,6 @@ fun TypeFoldable.visitTyTypeParameterWith(visitor: (TyTypeParameter) -> B override fun invoke(ty: Ty): Boolean = if (ty is TyTypeParameter) visitor(ty) else ty.innerVisitWith(this) }) -// -///** Deeply replace any [TyInfer] with the function [folder] */ -//fun TypeFoldable.foldTyInfersWith(folder: (TyInfer) -> Ty): T = -// foldWith(object : TypeFolder { -// override fun invoke(ty: Ty): Ty = -// (if (ty is TyInfer) folder(ty) else ty).innerFoldWith(this) -// }) - -/** - * Deeply replace any [TyTypeParameter] by [subst] mapping. - */ -fun TypeFoldable.substitute(subst: Substitution): T = - foldWith(object : TypeFolder { - override fun invoke(ty: Ty): Ty = - subst[ty] ?: ty.innerFoldWith(this) - }) fun TypeFoldable.containsTyOfClass(classes: List>): Boolean = visitWith(object : TypeVisitor { diff --git a/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt b/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt index 3046e2dd9..f5270b7db 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt @@ -12,7 +12,7 @@ import org.move.lang.core.psi.ext.* import org.move.lang.core.psi.mixins.ty import org.move.lang.core.types.ty.* -interface MvInferenceContextOwner: MvElement { +interface MvInferenceContextOwner : MvElement { fun parameterBindings(): List } @@ -41,7 +41,9 @@ private fun getOwnerInferenceContext(owner: MvInferenceContextOwner, msl: Boolea } when (owner) { is MvFunction -> { - owner.codeBlock?.let { inferCodeBlockTy(it, inferenceCtx, owner.returnTy) } + owner.codeBlock?.let { + inferCodeBlockTy(it, inferenceCtx, owner.returnTypeTy(inferenceCtx)) + } } is MvItemSpec -> { owner.itemSpecBlock?.let { inferSpecBlockStmts(it, inferenceCtx) } @@ -90,7 +92,7 @@ fun inferStmt(stmt: MvStmt, blockCtx: InferenceContext) { is MvExprStmt -> inferExprTy(stmt.expr, blockCtx) is MvSpecExprStmt -> inferExprTy(stmt.expr, blockCtx) is MvLetStmt -> { - val explicitTy = stmt.typeAnnotation?.type?.let { inferTypeTy(it, stmt.isMsl()) } + val explicitTy = stmt.typeAnnotation?.type?.let { inferTypeTy(it, blockCtx) } val initializerTy = stmt.initializer?.expr?.let { inferExprTy(it, blockCtx, explicitTy) } val pat = stmt.pat ?: return val patTy = inferPatTy(pat, blockCtx, explicitTy ?: initializerTy) @@ -99,7 +101,7 @@ fun inferStmt(stmt: MvStmt, blockCtx: InferenceContext) { } } -fun instantiateItemTy(item: MvNameIdentifierOwner, msl: Boolean): Ty { +fun instantiateItemTy(item: MvNameIdentifierOwner, inferenceCtx: InferenceContext): Ty { return when (item) { is MvStruct -> { val typeVars = item.typeParameters.map { TyInfer.TyVar(TyTypeParameter(it)) } @@ -112,7 +114,7 @@ fun instantiateItemTy(item: MvNameIdentifierOwner, msl: Boolean): Ty { val fieldName = field.name ?: return TyUnknown val fieldTy = item .fieldsMap[fieldName] - ?.declarationTy(msl) + ?.declarationTypeTy(inferenceCtx) ?.foldTyTypeParameterWith { findTypeVar(it.origin) } ?: TyUnknown fieldTys[fieldName] = fieldTy @@ -131,7 +133,7 @@ fun instantiateItemTy(item: MvNameIdentifierOwner, msl: Boolean): Ty { val paramTypes = mutableListOf() for (param in item.parameters) { val paramType = param.typeAnnotation?.type - ?.let { inferTypeTy(it, msl) } + ?.let { inferTypeTy(it, inferenceCtx) } ?.foldTyTypeParameterWith { findTypeVar(it.origin) } ?: TyUnknown paramTypes.add(paramType) } @@ -139,12 +141,12 @@ fun instantiateItemTy(item: MvNameIdentifierOwner, msl: Boolean): Ty { val retTy = if (returnMvType == null) { TyUnit } else { - inferTypeTy(returnMvType, msl).foldTyTypeParameterWith { findTypeVar(it.origin) } + inferTypeTy(returnMvType, inferenceCtx).foldTyTypeParameterWith { findTypeVar(it.origin) } } val acqTys = item.acquiresPathTypes.map { val acqItem = it.path.reference?.resolve() as? MvNameIdentifierOwner ?: return@map TyUnknown - instantiateItemTy(acqItem, msl) + instantiateItemTy(acqItem, inferenceCtx) .foldTyTypeParameterWith { tp -> findTypeVar(tp.origin) } } val typeArgs = item.typeParameters.map { findTypeVar(it) } @@ -321,8 +323,11 @@ sealed class TypeError(open val element: PsiElement) { class InferenceContext(val msl: Boolean) { var exprTypes = concurrentMapOf() val patTypes = mutableMapOf() + var typeTypes = mutableMapOf() + var callExprTypes = mutableMapOf() val bindingTypes = concurrentMapOf() + var typeErrors = mutableListOf() val unificationTable = UnificationTable() @@ -346,6 +351,10 @@ class InferenceContext(val msl: Boolean) { this.patTypes[pat] = ty } + fun cacheTypeTy(type: MvType, ty: Ty) { + this.typeTypes[type] = ty + } + fun cacheCallExprTy(expr: MvCallExpr, ty: TyFunction) { this.callExprTypes[expr] = ty } @@ -374,6 +383,7 @@ class InferenceContext(val msl: Boolean) { fun childContext(): InferenceContext { val childContext = InferenceContext(this.msl) childContext.exprTypes = this.exprTypes + childContext.typeTypes = this.typeTypes childContext.callExprTypes = this.callExprTypes childContext.typeErrors = this.typeErrors return childContext diff --git a/src/main/kotlin/org/move/lang/core/types/infer/TypeDeclarations.kt b/src/main/kotlin/org/move/lang/core/types/infer/TypeDeclarations.kt index 76b059776..656dbd161 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/TypeDeclarations.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/TypeDeclarations.kt @@ -7,9 +7,9 @@ import org.move.lang.core.psi.ext.mutable import org.move.lang.core.psi.ext.typeArguments import org.move.lang.core.types.ty.* -fun inferBuiltinTypeTy(moveType: MvPathType, msl: Boolean): Ty { +fun inferBuiltinTypeTy(moveType: MvPathType, inferenceCtx: InferenceContext): Ty { val refName = moveType.path.referenceName ?: return TyUnknown - if (msl && refName in SPEC_INTEGER_TYPE_IDENTIFIERS) return TyInteger.fromName("num") + if (inferenceCtx.msl && refName in SPEC_INTEGER_TYPE_IDENTIFIERS) return TyInteger.fromName("num") return when (refName) { in INTEGER_TYPE_IDENTIFIERS -> TyInteger.fromName(refName) "bool" -> TyBool @@ -19,45 +19,51 @@ fun inferBuiltinTypeTy(moveType: MvPathType, msl: Boolean): Ty { val itemTy = moveType.path.typeArguments .firstOrNull() ?.type - ?.let { inferTypeTy(it, msl) } ?: TyUnknown + ?.let { inferTypeTy(it, inferenceCtx) } ?: TyUnknown return TyVector(itemTy) } else -> TyUnknown } } -fun inferTypeTy(moveType: MvType, msl: Boolean): Ty { - return when (moveType) { - is MvPathType -> { - val struct = moveType.path.reference?.resolve() ?: return inferBuiltinTypeTy(moveType, msl) +fun inferTypeTy(moveType: MvType, inferenceCtx: InferenceContext): Ty { + val existingTy = inferenceCtx.typeTypes[moveType] + if (existingTy != null) { + return existingTy + } + val ty = when (moveType) { + is MvPathType -> run { + val struct = + moveType.path.reference?.resolve() ?: return@run inferBuiltinTypeTy(moveType, inferenceCtx) when (struct) { is MvTypeParameter -> TyTypeParameter(struct) is MvStruct -> { - val typeArgs = moveType.path.typeArguments.map { inferTypeTy(it.type, msl) } - val structTy = instantiateItemTy(struct, msl) as? TyStruct ?: return TyUnknown + val typeArgs = moveType.path.typeArguments.map { inferTypeTy(it.type, inferenceCtx) } + val structTy = instantiateItemTy(struct, inferenceCtx) as? TyStruct ?: return TyUnknown - val ctx = InferenceContext(msl) + val ctx = InferenceContext(inferenceCtx.msl) for ((tyVar, tyArg) in structTy.typeVars.zip(typeArgs)) { ctx.addConstraint(tyVar, tyArg) } ctx.processConstraints() - ctx.resolveTy(structTy) } else -> TyUnknown } } - is MvRefType -> { + is MvRefType -> run { val mutabilities = RefPermissions.valueOf(moveType.mutable) - val innerTypeRef = moveType.type ?: return TyReference(TyUnknown, mutabilities, msl) - val innerTy = inferTypeTy(innerTypeRef, msl) - TyReference(innerTy, mutabilities, msl) + val innerTypeRef = moveType.type ?: return@run TyReference(TyUnknown, mutabilities, inferenceCtx.msl) + val innerTy = inferTypeTy(innerTypeRef, inferenceCtx) + TyReference(innerTy, mutabilities, inferenceCtx.msl) } is MvTupleType -> { - val innerTypes = moveType.typeList.map { inferTypeTy(it, msl) } + val innerTypes = moveType.typeList.map { inferTypeTy(it, inferenceCtx) } TyTuple(innerTypes) } is MvUnitType -> TyUnit else -> TyUnknown } + inferenceCtx.cacheTypeTy(moveType, ty) + return ty } diff --git a/src/main/kotlin/org/move/lang/core/types/ty/TyFunction.kt b/src/main/kotlin/org/move/lang/core/types/ty/TyFunction.kt index 466d06569..24e60c591 100644 --- a/src/main/kotlin/org/move/lang/core/types/ty/TyFunction.kt +++ b/src/main/kotlin/org/move/lang/core/types/ty/TyFunction.kt @@ -20,7 +20,7 @@ class TyFunction( paramTypes.map { it.foldWith(folder) }, retType.foldWith(folder), acquiresTypes.map { it.foldWith(folder) }, - typeArgs.map(folder) + typeArgs.map { it.foldWith(folder) } ) } diff --git a/src/main/kotlin/org/move/lang/core/types/ty/TyStruct.kt b/src/main/kotlin/org/move/lang/core/types/ty/TyStruct.kt index 71b2c7703..30a4df151 100644 --- a/src/main/kotlin/org/move/lang/core/types/ty/TyStruct.kt +++ b/src/main/kotlin/org/move/lang/core/types/ty/TyStruct.kt @@ -15,11 +15,12 @@ data class TyStruct( override fun abilities(): Set = this.item.tyAbilities override fun innerFoldWith(folder: TypeFolder): Ty { + folder.depth += 1 return TyStruct( item, typeVars, - fieldTys.mapValues { folder(it.value) }, - typeArgs.map(folder) + fieldTys.mapValues { it.value.foldWith(folder) }, + typeArgs.map { it.foldWith(folder) } ) } diff --git a/src/main/kotlin/org/move/lang/core/types/ty/TyVector.kt b/src/main/kotlin/org/move/lang/core/types/ty/TyVector.kt index a3bdbc712..d1052070c 100644 --- a/src/main/kotlin/org/move/lang/core/types/ty/TyVector.kt +++ b/src/main/kotlin/org/move/lang/core/types/ty/TyVector.kt @@ -8,8 +8,10 @@ import org.move.lang.core.types.infer.TypeVisitor open class TyVector(val item: Ty) : Ty { override fun abilities() = item.abilities() - override fun innerFoldWith(folder: TypeFolder): Ty = - TyVector(item.foldWith(folder)) + override fun innerFoldWith(folder: TypeFolder): Ty { + folder.depth += 1 + return TyVector(item.foldWith(folder)) + } override fun innerVisitWith(visitor: TypeVisitor): Boolean = item.visitWith(visitor) diff --git a/src/main/kotlin/org/move/stdext/Collections.kt b/src/main/kotlin/org/move/stdext/Collections.kt index c8c64e5f2..022b80fc0 100644 --- a/src/main/kotlin/org/move/stdext/Collections.kt +++ b/src/main/kotlin/org/move/stdext/Collections.kt @@ -192,4 +192,4 @@ fun MutableMap>.putGrouped(key: K, value: V) { fun T?.wrapWithList(): List = this?.let { listOf(it) }.orEmpty() fun T?.wrapWithMutableList(): MutableList = this?.let { listOf(it) }.orEmpty().toMutableList() -fun List.withElement(element: T): List = listOf(this, listOf(element)).flatten() +fun List.withAdded(element: T): List = listOf(this, listOf(element)).flatten() diff --git a/src/test/kotlin/org/move/ide/docs/MoveDocumentationProviderTest.kt b/src/test/kotlin/org/move/ide/docs/MoveDocumentationProviderTest.kt index 3e5e4ee69..03fa1c916 100644 --- a/src/test/kotlin/org/move/ide/docs/MoveDocumentationProviderTest.kt +++ b/src/test/kotlin/org/move/ide/docs/MoveDocumentationProviderTest.kt @@ -124,6 +124,22 @@ class MvDocumentationProviderTest : MvDocumentationProviderTestCase() {

""" ) + fun `test function signature with return generic`() = doTest(""" +module 0x1::main { + struct Box has copy, drop, store { x: T } + struct Box3 has copy, drop, store { x: Box> } + + fun box3(x: T): Box3 { + //^ + Box3 { x: Box { x: Box { x } } } + } +} + """, expected = """ +
0x1::main
+fun box3<T>(x: T): Box3<T>
+
+ """) + private fun doTest(@Language("Move") code: String, @Language("Html") expected: String?) = doTest(code, expected, block = MvDocumentationProvider::generateDoc) } diff --git a/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt b/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt index 754666c2e..86eea25c7 100644 --- a/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/MvTypeCheckInspectionTest.kt @@ -949,12 +949,37 @@ module 0x1::main { fun `test deeply nested structure type is unknown due to memory issues`() = checkByText(""" module 0x1::main { - struct Box { x: T } - struct Box3 { x: Box> } -// struct Box7 { x: Box3> } -// struct Box15 { x: Box7> } + struct Box has copy, drop, store { x: T } + struct Box3 has copy, drop, store { x: Box> } + struct Box7 has copy, drop, store { x: Box3> } + struct Box15 has copy, drop, store { x: Box7> } + struct Box31 has copy, drop, store { x: Box15> } + struct Box63 has copy, drop, store { x: Box31> } + + fun box3(x: T): Box3 { + Box3 { x: Box { x: Box { x } } } + } + + fun box7(x: T): Box7 { + Box7 { x: box3(box3(x)) } + } + + fun box15(x: T): Box15 { + Box15 { x: box7(box7(x)) } + } + + fun box31(x: T): Box31 { + Box31 { x: box15(box15(x)) } + } + + fun box63(x: T): Box63 { + Box63 { x: box31(box31(x)) } + } + fun main() { - let a: Box3; + let a: Box63; + a; + //^ unknown } } """) From 3e7ca030f4f5c275e3495f2105cd29808d866d09 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Mon, 19 Sep 2022 22:13:20 +0200 Subject: [PATCH 17/26] disable redundant qualified path inspection, too many false positives for too little value --- src/main/resources/META-INF/plugin.xml | 2 +- .../RedundantQualifiedPathInspectionTest.kt | 76 +++++++++---------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 272d91cbc..3b35f3528 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -185,7 +185,7 @@ implementationClass="org.move.ide.inspections.MvLocalBindingNamingInspection"/> () {} - } - module 0x1::M2 { - use 0x1::M; - use 0x1::M::call; - fun m() { - 0x1::M/*caret*/::call(); - } - } - """, """ - module 0x1::M { - public fun call() {} - } - module 0x1::M2 { - use 0x1::M; - use 0x1::M::call; - fun m() { - /*caret*/call(); - } - } - """ - ) +// fun `test remove redundant qualifier with specified generic`() = checkFixByText( +// "Remove redundant qualifier", """ +// module 0x1::M { +// public fun call() {} +// } +// module 0x1::M2 { +// use 0x1::M; +// use 0x1::M::call; +// fun m() { +// 0x1::M/*caret*/::call(); +// } +// } +// """, """ +// module 0x1::M { +// public fun call() {} +// } +// module 0x1::M2 { +// use 0x1::M; +// use 0x1::M::call; +// fun m() { +// /*caret*/call(); +// } +// } +// """ +// ) - fun `test no redundant qualifier if import is in a different scope`() = checkByText(""" -module 0x1::string { - public fun call() {} -} -module 0x1::main { - #[test_only] - use 0x1::string; - - fun main() { - 0x1::string::call(); - } -} - """) +// fun `test no redundant qualifier if import is in a different scope`() = checkByText(""" +//module 0x1::string { +// public fun call() {} +//} +//module 0x1::main { +// #[test_only] +// use 0x1::string; +// +// fun main() { +// 0x1::string::call(); +// } +//} +// """) } From 9ecdd8d984beba9df12459182c915aaddee6fa52 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Mon, 19 Sep 2022 22:47:20 +0200 Subject: [PATCH 18/26] fix documentation rendering for function return types --- .../org/move/ide/docs/MvDocumentationProvider.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/org/move/ide/docs/MvDocumentationProvider.kt b/src/main/kotlin/org/move/ide/docs/MvDocumentationProvider.kt index e53e3b1e2..19c984f8b 100644 --- a/src/main/kotlin/org/move/ide/docs/MvDocumentationProvider.kt +++ b/src/main/kotlin/org/move/ide/docs/MvDocumentationProvider.kt @@ -32,9 +32,8 @@ class MvDocumentationProvider : AbstractDocumentationProvider() { override fun generateDoc(element: PsiElement?, originalElement: PsiElement?): String? { val buffer = StringBuilder() var docElement = element -// if (docElement is MvFunctionSignature) docElement = docElement.parent -// if (docElement is MvStructSignature) docElement = docElement.parent - if (docElement is MvBindingPat + if ( + docElement is MvBindingPat && docElement.owner is MvConst ) docElement = docElement.owner when (docElement) { @@ -155,7 +154,10 @@ private fun PsiElement.generateDocumentation( buffer += prefix when (this) { is MvType -> { - buffer += inferTypeTy(this, InferenceContext(this.isMsl())).typeLabel(this) + buffer += inferTypeTy(this, InferenceContext(this.isMsl())) + .typeLabel(this) + .replace("<", "<") + .replace(">", ">") } is MvFunctionParameterList -> From 7d20e844248e19ba0a33dc5aa2fe7c33997a8b3a Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Mon, 19 Sep 2022 22:54:04 +0200 Subject: [PATCH 19/26] fix error with option::none() incompatibility --- .../kotlin/org/move/lang/core/types/infer/InferenceContext.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt b/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt index f5270b7db..7a3a01115 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/InferenceContext.kt @@ -215,7 +215,7 @@ fun checkTysCompatible(rawExpectedTy: Ty, rawInferredTy: Ty, msl: Boolean = true return when { expectedTy is TyNever || inferredTy is TyNever -> Compat.Yes expectedTy is TyUnknown || inferredTy is TyUnknown -> Compat.Yes - expectedTy is TyInfer.TyVar -> { + expectedTy is TyInfer.TyVar && inferredTy !is TyInfer.TyVar -> { isCompatibleAbilities(expectedTy, inferredTy, msl) } /* expectedTy !is TyInfer.TyVar && */ inferredTy is TyInfer.TyVar -> { From da64652ce8e1dcd67e50d38a037c6bfb5545a9a4 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Mon, 19 Sep 2022 23:24:23 +0200 Subject: [PATCH 20/26] fix phantom type parameter inspection --- .../PhantomTypeParameterInspection.kt | 40 ++++++++++--------- .../PhantomTypeParameterInspectionTest.kt | 10 +++++ 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/org/move/ide/inspections/PhantomTypeParameterInspection.kt b/src/main/kotlin/org/move/ide/inspections/PhantomTypeParameterInspection.kt index 9f2c6eb65..ccb6a186f 100644 --- a/src/main/kotlin/org/move/ide/inspections/PhantomTypeParameterInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/PhantomTypeParameterInspection.kt @@ -1,6 +1,8 @@ package org.move.ide.inspections import com.intellij.codeInspection.ProblemsHolder +import com.intellij.psi.util.childrenOfType +import com.intellij.psi.util.descendants import com.intellij.psi.util.descendantsOfType import org.move.ide.inspections.fixes.PhantomFix import org.move.lang.core.psi.* @@ -15,28 +17,28 @@ class PhantomTypeParameterInspection : MvLocalInspectionTool() { val usedTypeParams = mutableSetOf() for (structField in o.fields) { - val fieldUsedTypeParams = mutableListOf() + val fieldUsedTypeParams = mutableSetOf() - // find all MvTypeParameter used in field declaration - structField.declarationTypeTy(InferenceContext(false)) - .visitTyTypeParameterWith { fieldUsedTypeParams.add(it.origin) } + val fieldType = structField.typeAnnotation?.type ?: continue + for (path in fieldType.descendantsOfType()) { + if (path.typeArguments.isNotEmpty()) continue + val typeParam = path.reference?.resolve() as? MvTypeParameter ?: continue + fieldUsedTypeParams.add(typeParam) + } // find all MvTypeArgument, check their phantom status - val fieldType = structField.typeAnnotation?.type - if (fieldType != null) { - val paths = fieldType.descendantsOfType() - for (path in paths) { - // stop if empty - if (path.typeArguments.isEmpty()) continue - // determine phantom status of every argument, drop if phantom - val outerStruct = path.reference?.resolve() as? MvStruct ?: continue - for ((i, typeArg) in path.typeArguments.withIndex()) { - val outerTypeParam = outerStruct.typeParameters.getOrNull(i) ?: continue - if (outerTypeParam.isPhantom) { - val typeParam = - typeArg.type.moveReference?.resolve() as? MvTypeParameter ?: continue - fieldUsedTypeParams.remove(typeParam) - } + val paths = fieldType.descendantsOfType() + for (path in paths) { + // stop if empty + if (path.typeArguments.isEmpty()) continue + // determine phantom status of every argument, drop if phantom + val outerStruct = path.reference?.resolve() as? MvStruct ?: continue + for ((i, typeArg) in path.typeArguments.withIndex()) { + val outerTypeParam = outerStruct.typeParameters.getOrNull(i) ?: continue + if (outerTypeParam.isPhantom) { + val typeParam = + typeArg.type.moveReference?.resolve() as? MvTypeParameter ?: continue + fieldUsedTypeParams.remove(typeParam) } } } diff --git a/src/test/kotlin/org/move/ide/inspections/PhantomTypeParameterInspectionTest.kt b/src/test/kotlin/org/move/ide/inspections/PhantomTypeParameterInspectionTest.kt index 2fc8e7f1f..b5a13bd00 100644 --- a/src/test/kotlin/org/move/ide/inspections/PhantomTypeParameterInspectionTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/PhantomTypeParameterInspectionTest.kt @@ -130,4 +130,14 @@ module 0x1::main { } """ ) + + fun `test deeply nested type`() = checkByText(""" +module 0x1::main { + struct Box has copy, drop, store { x: T } + struct Box3 has copy, drop, store { x: Box> } + struct Box7 has copy, drop, store { x: Box3> } + struct Box15 has copy, drop, store { x: Box7> } + struct Box31 has copy, drop, store { x: Box15> } +} + """) } From ac0ab004da90b6c6ed729b063cf2c6ab82ac502b Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Tue, 20 Sep 2022 16:55:09 +0200 Subject: [PATCH 21/26] fix acquires tys --- .../MvMissingAcquiresInspection.kt | 6 ++-- .../MvUnusedAcquiresTypeInspection.kt | 19 ++++++----- .../org/move/lang/core/psi/ext/MvCallExpr.kt | 22 +++++++------ .../move/lang/core/types/infer/Expressions.kt | 2 +- .../MvMissingAcquiresInspectionTest.kt | 11 +++++++ .../MvUnusedAcquiresTypeInspectionTest.kt | 22 +++++++++++++ .../MvUnusedImportInspectionTest.kt | 32 +++++++++++++++++++ .../move/lang/resolve/ResolveFunctionTest.kt | 14 ++++++++ 8 files changed, 105 insertions(+), 23 deletions(-) diff --git a/src/main/kotlin/org/move/ide/inspections/MvMissingAcquiresInspection.kt b/src/main/kotlin/org/move/ide/inspections/MvMissingAcquiresInspection.kt index f9e8ad478..043a0e74d 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvMissingAcquiresInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvMissingAcquiresInspection.kt @@ -10,8 +10,6 @@ import org.move.ide.presentation.fullnameNoArgs import org.move.ide.presentation.nameNoArgs import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.acquiresTys -import org.move.lang.core.psi.ext.isMsl -import org.move.lang.core.types.infer.inferenceCtx import org.move.lang.core.types.ty.Ty import org.move.lang.core.types.ty.TyUnknown @@ -26,8 +24,8 @@ class MvMissingAcquiresInspection : MvLocalInspectionTool() { val module = callExpr.containingModule ?: return val declaredTyFullnames = function.acquiresTys.map { it.fullnameNoArgs() } - val inferenceCtx = function.inferenceCtx(callExpr.isMsl()) - val missingTys = callExpr.acquiresTys(inferenceCtx) + val acquiresTys = callExpr.acquiresTys() ?: return + val missingTys = acquiresTys .filter { it.fullnameNoArgs() !in declaredTyFullnames } .filter { it !is TyUnknown } .filter { it.canBeAcquiredInModule(module) } diff --git a/src/main/kotlin/org/move/ide/inspections/MvUnusedAcquiresTypeInspection.kt b/src/main/kotlin/org/move/ide/inspections/MvUnusedAcquiresTypeInspection.kt index 17e3c252f..703c4ec13 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvUnusedAcquiresTypeInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvUnusedAcquiresTypeInspection.kt @@ -10,9 +10,9 @@ import org.move.ide.presentation.canBeAcquiredInModule import org.move.ide.presentation.fullnameNoArgs import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.acquiresTys -import org.move.lang.core.psi.ext.isMsl import org.move.lang.core.types.infer.inferTypeTy import org.move.lang.core.types.infer.inferenceCtx +import org.move.lang.core.types.ty.TyUnknown class MvUnusedAcquiresTypeInspection : MvLocalInspectionTool() { @@ -46,12 +46,15 @@ class MvUnusedAcquiresTypeInspection : MvLocalInspectionTool() { val function = o.parent as? MvFunction ?: return val module = function.module ?: return val codeBlock = function.codeBlock ?: return - val inferenceCtx = function.inferenceCtx(codeBlock.isMsl()) - val blockAcquiredTys = codeBlock - .descendantsOfType() - .flatMap { it.acquiresTys(inferenceCtx) } - .map { it.fullnameNoArgs() } - .toSet() + val inferenceCtx = function.inferenceCtx(false) + + val acquiredTys = mutableSetOf() + for (callExpr in codeBlock.descendantsOfType()) { + val callAcquiresTys = + callExpr.acquiresTys() ?: return + val acqTyNames = callAcquiresTys.map { it.fullnameNoArgs() } + acquiredTys.addAll(acqTyNames) + } val unusedAcquiresIndices = mutableListOf() val visitedTypeNames = mutableSetOf() @@ -71,7 +74,7 @@ class MvUnusedAcquiresTypeInspection : MvLocalInspectionTool() { } visitedTypeNames.add(typeName) // check for unused - if (typeName !in blockAcquiredTys) { + if (typeName !in acquiredTys) { unusedAcquiresIndices.add(i) continue } diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvCallExpr.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvCallExpr.kt index fb641fbfd..fe9e7b3d0 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvCallExpr.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvCallExpr.kt @@ -4,22 +4,24 @@ import org.move.lang.core.psi.MvCallExpr import org.move.lang.core.psi.MvExpr import org.move.lang.core.psi.MvTypeArgument import org.move.lang.core.psi.MvValueArgument -import org.move.lang.core.psi.MvValueArgumentList -import org.move.lang.core.types.infer.InferenceContext -import org.move.lang.core.types.infer.inferCallExprTy +import org.move.lang.core.types.infer.ownerInferenceCtx import org.move.lang.core.types.ty.Ty -import org.move.lang.core.types.ty.TyFunction +import org.move.lang.core.types.ty.TyUnknown val MvCallExpr.typeArguments: List get() = this.path.typeArguments -val MvCallExpr.valueArguments: List get() = - this.valueArgumentList?.valueArgumentList.orEmpty() +val MvCallExpr.valueArguments: List + get() = + this.valueArgumentList?.valueArgumentList.orEmpty() val MvCallExpr.callArgumentExprs: List get() = this.valueArgumentList ?.valueArgumentList.orEmpty().map { it.expr } -val MvValueArgumentList.argumentExprs: List get() = this.valueArgumentList.map { it.expr } - -fun MvCallExpr.acquiresTys(ctx: InferenceContext): List = - (inferCallExprTy(this, ctx, null) as? TyFunction)?.acquiresTypes.orEmpty() +fun MvCallExpr.acquiresTys(): List? { + val msl = this.isMsl() + val inferenceCtx = this.ownerInferenceCtx(msl) + return inferenceCtx.callExprTypes[this] + ?.acquiresTypes + ?.takeIf { !it.contains(TyUnknown) } +} diff --git a/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt b/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt index 409d04c3b..7eace8763 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt @@ -88,7 +88,7 @@ private fun inferBorrowExprTy(borrowExpr: MvBorrowExpr, ctx: InferenceContext): return TyReference(innerExprTy, mutabilities, ctx.msl) } -fun inferCallExprTy( +private fun inferCallExprTy( callExpr: MvCallExpr, parentCtx: InferenceContext, expectedTy: Ty? diff --git a/src/test/kotlin/org/move/ide/inspections/MvMissingAcquiresInspectionTest.kt b/src/test/kotlin/org/move/ide/inspections/MvMissingAcquiresInspectionTest.kt index 49dcd7673..c72245033 100644 --- a/src/test/kotlin/org/move/ide/inspections/MvMissingAcquiresInspectionTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/MvMissingAcquiresInspectionTest.kt @@ -157,4 +157,15 @@ class MvMissingAcquiresInspectionTest: InspectionTestBase(MvMissingAcquiresInspe } } """) + + fun `test missing acquires for borrow_global with dot expr`() = checkWarnings(""" +module 0x1::main { + struct StakePool has key { + locked_until_secs: u64, + } + fun get_lockup_secs(pool_address: address): u64 { + borrow_global(pool_address).locked_until_secs + } +} + """) } diff --git a/src/test/kotlin/org/move/ide/inspections/MvUnusedAcquiresTypeInspectionTest.kt b/src/test/kotlin/org/move/ide/inspections/MvUnusedAcquiresTypeInspectionTest.kt index f89a3971a..21752f584 100644 --- a/src/test/kotlin/org/move/ide/inspections/MvUnusedAcquiresTypeInspectionTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/MvUnusedAcquiresTypeInspectionTest.kt @@ -77,4 +77,26 @@ class MvUnusedAcquiresTypeInspectionTest : InspectionTestBase(MvUnusedAcquiresTy } """ ) + + fun `test no unused acquires for borrow_global with dot expr`() = checkWarnings(""" +module 0x1::main { + struct StakePool has key { + locked_until_secs: u64, + } + fun get_lockup_secs(pool_address: address): u64 acquires StakePool { + borrow_global(pool_address).locked_until_secs + } +} + """) + + fun `test no unused acquires with `() = checkWarnings(""" +module 0x1::main { + struct StakePool has key { + locked_until_secs: u64, + } + fun get_lockup_secs(pool_address: address) acquires StakePool { + borrow_global(pool_address); + } +} + """) } diff --git a/src/test/kotlin/org/move/ide/inspections/MvUnusedImportInspectionTest.kt b/src/test/kotlin/org/move/ide/inspections/MvUnusedImportInspectionTest.kt index 3ffdf7568..481cb832b 100644 --- a/src/test/kotlin/org/move/ide/inspections/MvUnusedImportInspectionTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/MvUnusedImportInspectionTest.kt @@ -402,6 +402,38 @@ module 0x1::main { use 0x1::string; string::call(); } +} + """) + + fun `test no unused import used in both main and test scopes expr`() = checkWarnings(""" +module 0x1::string { + struct String {} + public fun call() {} +} +module 0x1::main { + use 0x1::string; + fun d() { + string::call(); + } + #[test_only] + fun main() { + string::call(); + } +} + """) + + fun `test no unused import used in both main and test scopes type`() = checkWarnings(""" +module 0x1::string { + struct String {} + public fun call() {} +} +module 0x1::main { + use 0x1::string; + struct S { val: string::String } + #[test_only] + fun main() { + string::call(); + } } """) } diff --git a/src/test/kotlin/org/move/lang/resolve/ResolveFunctionTest.kt b/src/test/kotlin/org/move/lang/resolve/ResolveFunctionTest.kt index 4ba82e0b7..51112f194 100644 --- a/src/test/kotlin/org/move/lang/resolve/ResolveFunctionTest.kt +++ b/src/test/kotlin/org/move/lang/resolve/ResolveFunctionTest.kt @@ -497,6 +497,20 @@ module 0x1::main { utf8(); //^ } +} + """) + + fun `test resolve with self alias`() = checkByCode(""" +module 0x1::string { + public fun utf8() {} + //X +} +module 0x1::main { + use 0x1::string::Self as mystring; + fun main() { + mystring::utf8(); + //^ + } } """) } From 6cfec32d6f2d0b6ec040d0ca1c90052d8235c5e8 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Tue, 20 Sep 2022 17:07:40 +0200 Subject: [PATCH 22/26] resolve from local import correctly --- .../org/move/lang/core/resolve/NameResolution.kt | 6 +++++- .../org/move/lang/resolve/ResolveModulesTest.kt | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/move/lang/core/resolve/NameResolution.kt b/src/main/kotlin/org/move/lang/core/resolve/NameResolution.kt index 17aba85f9..a7f43c8c8 100644 --- a/src/main/kotlin/org/move/lang/core/resolve/NameResolution.kt +++ b/src/main/kotlin/org/move/lang/core/resolve/NameResolution.kt @@ -260,7 +260,11 @@ fun processLexicalDeclarations( ((entry.name !in visited) && processor.match(entry).also { visited += entry.name }) } - return processorWithShadowing.matchAll(itemVis, namedElements) + return processorWithShadowing.matchAll( + itemVis, + namedElements, + scope.itemImportNames() + ) } is MvItemSpec -> { diff --git a/src/test/kotlin/org/move/lang/resolve/ResolveModulesTest.kt b/src/test/kotlin/org/move/lang/resolve/ResolveModulesTest.kt index c21d34572..dc0956456 100644 --- a/src/test/kotlin/org/move/lang/resolve/ResolveModulesTest.kt +++ b/src/test/kotlin/org/move/lang/resolve/ResolveModulesTest.kt @@ -298,4 +298,18 @@ module 0x1::M { #[test_only] module 0x1::MTest {} """) + + fun `test resolve module import inside code block`() = checkByCode(""" +module 0x1::string { + //X + public fun utf8() {} +} +module 0x1::main { + fun main() { + use 0x1::string; + string::utf8(); + //^ + } +} + """) } From 8c0a4fa9ad605ef23f379254c5336913508059f8 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Sun, 25 Sep 2022 19:06:34 +0200 Subject: [PATCH 23/26] bug fixes --- changelog/1.20.0.md | 4 +- .../inspections/MvUnusedImportInspection.kt | 8 ++- .../move/ide/inspections/fixes/RenameFix.kt | 4 +- .../imports/MvPathUsageAnalysis.kt | 72 +++++++++++++------ .../move/ide/refactoring/ImportOptimizer.kt | 6 +- .../org/move/lang/core/psi/MvImportsOwner.kt | 9 ++- .../move/lang/core/psi/ext/MoveItemImport.kt | 2 + .../org/move/lang/core/psi/ext/MvUseAlias.kt | 9 +++ .../org/move/lang/core/psi/ext/PsiElement.kt | 4 ++ .../move/lang/core/resolve/NameResolution.kt | 7 +- .../move/lang/core/types/infer/Expressions.kt | 34 +++++---- .../MvUnusedImportInspectionTest.kt | 22 +++++- .../lang/types/ExpressionTypeInferenceTest.kt | 30 ++++++++ 13 files changed, 163 insertions(+), 48 deletions(-) create mode 100644 src/main/kotlin/org/move/lang/core/psi/ext/MvUseAlias.kt diff --git a/changelog/1.20.0.md b/changelog/1.20.0.md index 7f796fe17..9f6f7e872 100644 --- a/changelog/1.20.0.md +++ b/changelog/1.20.0.md @@ -22,7 +22,9 @@ TODO: screenshot * Type inference support for vector literals. -* Type check calls with not enough arguments. +* Type check calls with not enough arguments. + +* Type inference for `loop {}` expr. ## Fixes diff --git a/src/main/kotlin/org/move/ide/inspections/MvUnusedImportInspection.kt b/src/main/kotlin/org/move/ide/inspections/MvUnusedImportInspection.kt index c0a53f7f9..ed468372f 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvUnusedImportInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvUnusedImportInspection.kt @@ -6,6 +6,7 @@ import com.intellij.psi.PsiElement import com.intellij.psi.util.descendantsOfType import org.move.ide.inspections.imports.ItemUsages import org.move.ide.inspections.imports.ScopePathUsages +import org.move.ide.inspections.imports.importInfo import org.move.ide.inspections.imports.pathUsages import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.ancestorStrict @@ -101,15 +102,16 @@ class MvUnusedImportInspection : MvLocalInspectionTool() { } fun MvElement.isImportedItemUsed(): Boolean { - val owner = this.ancestorStrict() ?: return true - val pathUsages = owner.pathUsages.get(this.itemScope) + val parentImportsOwner = this.ancestorStrict() ?: return true + val itemScope = this.itemScope + val pathUsages = parentImportsOwner.pathUsages.get(itemScope) + return when (this) { is MvModuleUseSpeck -> { val useAlias = this.useAlias val moduleName = (if (useAlias != null) useAlias.name else this.fqModuleRef?.referenceName) ?: return true -// val moduleName = this.fqModuleRef?.referenceName ?: return true // null if import is never used val usageResolvedItems = pathUsages.nameUsages[moduleName] ?: return false if (usageResolvedItems.isEmpty()) { diff --git a/src/main/kotlin/org/move/ide/inspections/fixes/RenameFix.kt b/src/main/kotlin/org/move/ide/inspections/fixes/RenameFix.kt index 740923070..d720a7f28 100644 --- a/src/main/kotlin/org/move/ide/inspections/fixes/RenameFix.kt +++ b/src/main/kotlin/org/move/ide/inspections/fixes/RenameFix.kt @@ -11,6 +11,8 @@ import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile import com.intellij.psi.PsiNamedElement import com.intellij.refactoring.RefactoringFactory +import org.move.lang.core.psi.MvNamedElement +import org.move.lang.core.psi.rename import org.move.openapiext.nonBlocking /** @@ -31,6 +33,6 @@ class RenameFix( project.nonBlocking( { startElement }, { - RefactoringFactory.getInstance(project).createRename(it, newName).run() + (startElement as? MvNamedElement)?.rename(newName) }) } diff --git a/src/main/kotlin/org/move/ide/inspections/imports/MvPathUsageAnalysis.kt b/src/main/kotlin/org/move/ide/inspections/imports/MvPathUsageAnalysis.kt index 4a03ba909..94de4f802 100644 --- a/src/main/kotlin/org/move/ide/inspections/imports/MvPathUsageAnalysis.kt +++ b/src/main/kotlin/org/move/ide/inspections/imports/MvPathUsageAnalysis.kt @@ -3,10 +3,7 @@ package org.move.ide.inspections.imports import com.intellij.psi.util.CachedValuesManager.getProjectPsiDependentCache import com.intellij.psi.util.PsiTreeUtil import org.move.lang.core.psi.* -import org.move.lang.core.psi.ext.allModuleSpecBlocks -import org.move.lang.core.psi.ext.itemScope -import org.move.lang.core.psi.ext.module -import org.move.lang.core.psi.ext.moduleSpec +import org.move.lang.core.psi.ext.* import org.move.lang.core.resolve.ItemScope typealias ItemUsages = MutableMap> @@ -67,31 +64,57 @@ val MvImportsOwner.pathUsages: PathUsages return localPathUsages } +data class ImportInfo( + val mainImports: Map, + val testImports: Map +) { + fun getImports(itemScope: ItemScope): Map { + return when (itemScope) { + ItemScope.MAIN -> mainImports + ItemScope.TEST -> testImports + } + } +} + +val MvImportsOwner.importInfo: ImportInfo + get() { + return getProjectPsiDependentCache(this) { importsOwner -> + val mainImports = mutableMapOf() + val testImports = mutableMapOf() + for (useStmt in importsOwner.useStmtList) { + val scopeImports = if (useStmt.isTestOnly) testImports else mainImports + for (useItem in useStmt.childUseItems) { + val name = useItem.name ?: continue + scopeImports[name] = useItem + } + val moduleSpeck = useStmt.moduleUseSpeck ?: continue + val name = moduleSpeck.name ?: continue + scopeImports[name] = moduleSpeck + } + ImportInfo(mainImports, testImports) + } + } + private fun MvImportsOwner.localPathUsages(): PathUsages { - return getProjectPsiDependentCache(this) { + return getProjectPsiDependentCache(this) { importsOwner -> val mainNameUsages = mutableMapOf>() val mainTypeUsages = mutableMapOf>() val testNameUsages = mutableMapOf>() val testTypeUsages = mutableMapOf>() - for (child in it.children) { - PsiTreeUtil.processElements(child) { element -> + for (child in importsOwner.children) { + PsiTreeUtil.processElements(child, MvPath::class.java) { path -> + val nameUsages = + if (path.itemScope == ItemScope.TEST) testNameUsages else mainNameUsages + val typeUsages = + if (path.itemScope == ItemScope.TEST) testTypeUsages else mainTypeUsages when { - element is MvPathType -> { - val typeUsages = - if (element.itemScope == ItemScope.TEST) testTypeUsages else mainTypeUsages - putUsage(element.path, typeUsages) - true - } - element is MvPath && element.parent !is MvPathType -> { - val nameUsages = - if (element.itemScope == ItemScope.TEST) testNameUsages else mainNameUsages - putUsage(element, nameUsages) - true - } - else -> true + path.moduleRef != null -> putUsage(path, importsOwner, nameUsages) + path.parent is MvPathType -> putUsage(path, importsOwner, typeUsages) + else -> putUsage(path, importsOwner, nameUsages) } + true } } PathUsages( @@ -101,7 +124,14 @@ private fun MvImportsOwner.localPathUsages(): PathUsages { } } -private fun putUsage(element: MvPath, itemUsages: ItemUsages) { +private fun putUsage(element: MvPath, currentImportsOwner: MvImportsOwner, itemUsages: ItemUsages) { + for (ancestor in element.ancestorsOfType()) { + if (ancestor == currentImportsOwner) break + + val imports = ancestor.importInfo + + } + val moduleRef = element.moduleRef when { // MODULE::ITEM diff --git a/src/main/kotlin/org/move/ide/refactoring/ImportOptimizer.kt b/src/main/kotlin/org/move/ide/refactoring/ImportOptimizer.kt index 6bfad6a6f..4d7bcb61f 100644 --- a/src/main/kotlin/org/move/ide/refactoring/ImportOptimizer.kt +++ b/src/main/kotlin/org/move/ide/refactoring/ImportOptimizer.kt @@ -45,9 +45,9 @@ class ImportOptimizer : ImportOptimizer { sortImports(importsOwner) } - private fun removeUnusedImports(useStmtOwner: MvImportsOwner) { - val psiFactory = useStmtOwner.project.psiFactory - val useStmts = useStmtOwner.useStmtList + private fun removeUnusedImports(importsOwner: MvImportsOwner) { + val psiFactory = importsOwner.project.psiFactory + val useStmts = importsOwner.useStmtList for (useStmt in useStmts) { val moduleSpeck = useStmt.moduleUseSpeck if (moduleSpeck != null) { diff --git a/src/main/kotlin/org/move/lang/core/psi/MvImportsOwner.kt b/src/main/kotlin/org/move/lang/core/psi/MvImportsOwner.kt index 042dabace..79a959753 100644 --- a/src/main/kotlin/org/move/lang/core/psi/MvImportsOwner.kt +++ b/src/main/kotlin/org/move/lang/core/psi/MvImportsOwner.kt @@ -1,6 +1,7 @@ package org.move.lang.core.psi import org.move.lang.core.psi.ext.address +import org.move.lang.core.psi.ext.isSelf interface MvImportsOwner : MvElement { val useStmtList: List @@ -52,7 +53,13 @@ fun MvImportsOwner.itemImportsAliases(): List = itemImports().mapNot fun MvImportsOwner.selfItemImports(): List = itemImports() - .filter { it.useAlias == null && it.text == "Self" } + .filter { it.isSelf } + .filter { it.useAlias == null } + +fun MvImportsOwner.selfItemImportAliases(): List = + itemImports() + .filter { it.isSelf } + .mapNotNull { it.useAlias } fun MvImportsOwner.itemImportsWithoutAliases(): List = itemImports().filter { it.useAlias == null } diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MoveItemImport.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MoveItemImport.kt index 4ff5fb443..05006c4f7 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MoveItemImport.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MoveItemImport.kt @@ -27,6 +27,8 @@ val MvUseItem.moduleName: String return useStmt?.itemUseSpeck?.fqModuleRef?.referenceName.orEmpty() } +val MvUseItem.isSelf: Boolean get() = this.identifier.text == "Self" + class MvUseItemReferenceElement(element: MvUseItem) : MvReferenceCached(element) { override fun resolveInner(): List { val moduleRef = element.moduleImport().fqModuleRef diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvUseAlias.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvUseAlias.kt new file mode 100644 index 000000000..54c6a5d66 --- /dev/null +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvUseAlias.kt @@ -0,0 +1,9 @@ +package org.move.lang.core.psi.ext + +import org.move.lang.core.psi.MvModuleUseSpeck +import org.move.lang.core.psi.MvUseAlias +import org.move.lang.core.psi.MvUseItem + +val MvUseAlias.useItem: MvUseItem? get() = this.parent as? MvUseItem + +val MvUseAlias.moduleUseSpeck: MvModuleUseSpeck? get() = this.parent as? MvModuleUseSpeck diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/PsiElement.kt b/src/main/kotlin/org/move/lang/core/psi/ext/PsiElement.kt index 9b326a3f9..2c08b1939 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/PsiElement.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/PsiElement.kt @@ -33,6 +33,10 @@ val PsiElement.ancestors: Sequence if (it is PsiFile) null else it.parent } +inline fun PsiElement.ancestorsOfType(): Sequence { + return this.ancestors.filterIsInstance() +} + fun PsiElement.findFirstParent(strict: Boolean = true, cond: Condition) = PsiTreeUtil.findFirstParent(this, strict, cond) diff --git a/src/main/kotlin/org/move/lang/core/resolve/NameResolution.kt b/src/main/kotlin/org/move/lang/core/resolve/NameResolution.kt index a7f43c8c8..47a18bef0 100644 --- a/src/main/kotlin/org/move/lang/core/resolve/NameResolution.kt +++ b/src/main/kotlin/org/move/lang/core/resolve/NameResolution.kt @@ -95,11 +95,11 @@ fun resolveIntoFQModuleRef(moduleRef: MvModuleRef): MvFQModuleRef? { return moduleRef } // module refers to ModuleImport - val resolved = resolveSingleItem(moduleRef, setOf(Namespace.MODULE)) + var resolved = resolveSingleItem(moduleRef, setOf(Namespace.MODULE)) if (resolved is MvUseAlias) { - return (resolved.parent as MvModuleUseSpeck).fqModuleRef + resolved = resolved.moduleUseSpeck ?: resolved.useItem } - if (resolved is MvUseItem && resolved.text == "Self") { + if (resolved is MvUseItem && resolved.isSelf) { return resolved.moduleImport().fqModuleRef } if (resolved !is MvModuleUseSpeck) return null @@ -383,6 +383,7 @@ fun processLexicalDeclarations( listOf( scope.moduleImportNames(), scope.selfItemImports(), + scope.selfItemImportAliases(), ).flatten(), ) else -> false diff --git a/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt b/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt index 7eace8763..a417fb51b 100644 --- a/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt +++ b/src/main/kotlin/org/move/lang/core/types/infer/Expressions.kt @@ -36,7 +36,8 @@ fun inferExprTy(expr: MvExpr, parentCtx: InferenceContext, expectedTy: Ty? = nul is MvBangExpr -> TyBool is MvIfExpr -> inferIfExprTy(expr, parentCtx, expectedTy) - is MvWhileExpr -> inferWhileExprTy(expr, parentCtx) + is MvWhileExpr -> inferLoopExpr(expr, parentCtx) + is MvLoopExpr -> inferLoopExpr(expr, parentCtx) is MvReturnExpr -> { val fnReturnTy = expr.containingFunction?.returnTypeTy(parentCtx) expr.expr?.let { inferExprTy(it, parentCtx, fnReturnTy) } @@ -408,21 +409,30 @@ private fun inferIfExprTy(ifExpr: MvIfExpr, ctx: InferenceContext, expectedTy: T return combineTys(ifExprTy, elseExprTy, ctx.msl) } -private fun inferWhileExprTy(whileExpr: MvWhileExpr, ctx: InferenceContext): Ty { - val conditionExpr = whileExpr.condition?.expr - if (conditionExpr != null) { - inferExprTy(conditionExpr, ctx, TyBool) +private fun inferLoopExpr(expr: MvExpr, ctx: InferenceContext): Ty { + if (expr is MvWhileExpr) { + val conditionExpr = expr.condition?.expr + if (conditionExpr != null) { + inferExprTy(conditionExpr, ctx, TyBool) + } + } + val (codeBlock, inlineBlockExpr) = when (expr) { + is MvWhileExpr -> { + val conditionExpr = expr.condition?.expr + if (conditionExpr != null) { + inferExprTy(conditionExpr, ctx, TyBool) + } + Pair(expr.codeBlock, expr.inlineBlock?.expr) + } + is MvLoopExpr -> Pair(expr.codeBlock, expr.inlineBlock?.expr) + else -> error("unreachable") } - val whileCodeBlock = whileExpr.codeBlock - val whileInlineBlockExpr = whileExpr.inlineBlock?.expr when { - whileCodeBlock != null -> { + codeBlock != null -> { val blockCtx = ctx.childContext() - inferCodeBlockTy(whileCodeBlock, blockCtx, TyUnit) - } - whileInlineBlockExpr != null -> { - inferExprTy(whileInlineBlockExpr, ctx, TyUnit) + inferCodeBlockTy(codeBlock, blockCtx, TyUnit) } + inlineBlockExpr != null -> inferExprTy(inlineBlockExpr, ctx, TyUnit) } return TyUnit } diff --git a/src/test/kotlin/org/move/ide/inspections/MvUnusedImportInspectionTest.kt b/src/test/kotlin/org/move/ide/inspections/MvUnusedImportInspectionTest.kt index 481cb832b..75dc6a176 100644 --- a/src/test/kotlin/org/move/ide/inspections/MvUnusedImportInspectionTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/MvUnusedImportInspectionTest.kt @@ -378,13 +378,29 @@ module 0x1::main { } """) - fun `test unused import if imported locally`() = checkWarnings(""" +// fun `test unused import if imported locally`() = checkWarnings(""" +//module 0x1::string { +// public fun call() {} +//} +//module 0x1::main { +// use 0x1::string; +// fun main() { +// use 0x1::string; +// string::call(); +// } +//} +// """) + + fun `test no unused import if used in two local places`() = checkWarnings(""" module 0x1::string { public fun call() {} } module 0x1::main { - use 0x1::string; - fun main() { + use 0x1::string; + fun a() { + string::call(); + } + fun b() { use 0x1::string; string::call(); } diff --git a/src/test/kotlin/org/move/lang/types/ExpressionTypeInferenceTest.kt b/src/test/kotlin/org/move/lang/types/ExpressionTypeInferenceTest.kt index 58755728c..8ba5cff79 100644 --- a/src/test/kotlin/org/move/lang/types/ExpressionTypeInferenceTest.kt +++ b/src/test/kotlin/org/move/lang/types/ExpressionTypeInferenceTest.kt @@ -209,6 +209,36 @@ class ExpressionTypeInferenceTest: TypificationTestCase() { } """) + fun `test integer multi statement inside if while block`() = testExpr(""" + module 0x1::M { + fun put(i: u64, val: u64) {} + fun main() { + let i = 0; + while (i < 10) { + put(i, 10); + i = i + 1; + }; + i; + //^ u64 + } + } + """) + + fun `test integer multi statement inside loop block`() = testExpr(""" + module 0x1::M { + fun put(i: u64, val: u64) {} + fun main() { + let i = 0; + loop { + put(i, 10); + i = i + 1; + }; + i; + //^ u64 + } + } + """) + fun `test integer multi statement inside else expr block`() = testExpr(""" module 0x1::M { fun put(i: u64, val: u64) {} From b86d7855abff067a2b21342ef7af54c60ff8eff6 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Sun, 25 Sep 2022 19:42:59 +0200 Subject: [PATCH 24/26] postpone some test fixes --- .../fixes/RemoveParameterFixTest.kt | 62 +++++++++---------- .../lang/completion/KeywordCompletionTest.kt | 30 ++++----- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/test/kotlin/org/move/ide/inspections/fixes/RemoveParameterFixTest.kt b/src/test/kotlin/org/move/ide/inspections/fixes/RemoveParameterFixTest.kt index baab112b3..82768c190 100644 --- a/src/test/kotlin/org/move/ide/inspections/fixes/RemoveParameterFixTest.kt +++ b/src/test/kotlin/org/move/ide/inspections/fixes/RemoveParameterFixTest.kt @@ -80,37 +80,37 @@ class RemoveParameterFixTest: InspectionTestBase(MvUnusedVariableInspection::cla """ ) - fun `test second of two multiline`() = checkFixByText( - "Remove parameter", """ - module 0x1::M { - fun call( - b: u8, - /*caret*/a: u8, - ): u8 { - b - } - fun main() { - call( - 1, - 2 - ); - } - } - """, """ - module 0x1::M { - fun call( - b: u8 - ): u8 { - b - } - fun main() { - call( - 1 - ); - } - } - """ - ) +// fun `test second of two multiline`() = checkFixByText( +// "Remove parameter", """ +// module 0x1::M { +// fun call( +// b: u8, +// /*caret*/a: u8, +// ): u8 { +// b +// } +// fun main() { +// call( +// 1, +// 2 +// ); +// } +// } +// """, """ +// module 0x1::M { +// fun call( +// b: u8 +// ): u8 { +// b +// } +// fun main() { +// call( +// 1 +// ); +// } +// } +// """ +// ) fun `test second of three`() = checkFixByText( "Remove parameter", """ diff --git a/src/test/kotlin/org/move/lang/completion/KeywordCompletionTest.kt b/src/test/kotlin/org/move/lang/completion/KeywordCompletionTest.kt index 0ac3b19dc..111a1ad04 100644 --- a/src/test/kotlin/org/move/lang/completion/KeywordCompletionTest.kt +++ b/src/test/kotlin/org/move/lang/completion/KeywordCompletionTest.kt @@ -579,19 +579,19 @@ class KeywordCompletionTest : CompletionTestCase() { } """) - fun `test bool completion in field initializer`() = doSingleCompletion(""" -module 0x1::main { - struct Container { val: Type } - fun main() { - Container { val: fa/*caret*/ }; - } -} - """, """ -module 0x1::main { - struct Container { val: Type } - fun main() { - Container { val: false/*caret*/ }; - } -} - """) +// fun `test bool completion in field initializer`() = doSingleCompletion(""" +//module 0x1::main { +// struct Container { val: Type } +// fun main() { +// Container { val: fa/*caret*/ }; +// } +//} +// """, """ +//module 0x1::main { +// struct Container { val: Type } +// fun main() { +// Container { val: false/*caret*/ }; +// } +//} +// """) } From 131c6cbb36214ee68a5f2f33ab25e0bffe71b7c4 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Sun, 25 Sep 2022 20:34:57 +0200 Subject: [PATCH 25/26] optimize imports --- gradle.properties | 2 +- src/main/kotlin/org/move/ide/formatter/impl/spacing.kt | 1 - .../org/move/ide/inspections/MvLocalInspectionTool.kt | 6 +----- .../ide/inspections/MvUnusedAcquiresTypeInspection.kt | 1 - .../org/move/ide/inspections/MvUnusedImportInspection.kt | 1 - .../move/ide/inspections/MvUnusedVariableInspection.kt | 2 +- .../ide/inspections/PhantomTypeParameterInspection.kt | 9 ++++----- .../org/move/ide/inspections/fixes/RemoveParameterFix.kt | 1 - .../kotlin/org/move/ide/inspections/fixes/RenameFix.kt | 1 - .../org/move/lang/core/completion/LookupElements.kt | 2 +- .../completion/providers/MvPathCompletionProvider.kt | 2 +- src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt | 4 +++- src/main/kotlin/org/move/lang/core/psi/ext/MoveExpr.kt | 2 +- .../org/move/lang/core/psi/ext/MoveStructLiteralField.kt | 6 ------ .../kotlin/org/move/lang/core/psi/ext/MvBinaryExpr.kt | 1 - .../lang/core/psi/ext/MvItemSpecFunctionParameter.kt | 5 ----- .../move/lang/core/psi/ext/MvItemSpecTypeParameter.kt | 6 ------ .../kotlin/org/move/lang/core/psi/ext/MvLetStatement.kt | 1 - .../kotlin/org/move/lang/core/psi/ext/MvSpecFunction.kt | 2 -- .../org/move/utils/tests/annotation/AnnotatorTestCase.kt | 2 -- .../org/move/utils/tests/types/TypificationTestCase.kt | 2 +- 21 files changed, 14 insertions(+), 45 deletions(-) diff --git a/gradle.properties b/gradle.properties index 163aa24eb..17a5c7cfd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,4 +14,4 @@ propertiesPluginEnvironmentNameProperty=shortPlatformVersion # properties files # supported versions are 212, 213, 221, 222, default is 212 # pass ORG_GRADLE_PROJECT_shortPlatformVersion environment variable to overwrite -shortPlatformVersion=222 +shortPlatformVersion=213 diff --git a/src/main/kotlin/org/move/ide/formatter/impl/spacing.kt b/src/main/kotlin/org/move/ide/formatter/impl/spacing.kt index 92ca02d6c..67f735646 100644 --- a/src/main/kotlin/org/move/ide/formatter/impl/spacing.kt +++ b/src/main/kotlin/org/move/ide/formatter/impl/spacing.kt @@ -14,7 +14,6 @@ import com.intellij.psi.tree.IElementType import com.intellij.psi.tree.TokenSet import org.move.ide.formatter.MvFmtContext import org.move.lang.MvElementTypes.* -import org.move.lang.core.MOVE_BINARY_OPS import org.move.lang.core.MOVE_COMMENTS import org.move.lang.core.MOVE_KEYWORDS import org.move.lang.core.psi.MvAddressBlock diff --git a/src/main/kotlin/org/move/ide/inspections/MvLocalInspectionTool.kt b/src/main/kotlin/org/move/ide/inspections/MvLocalInspectionTool.kt index df86af561..ad6349245 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvLocalInspectionTool.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvLocalInspectionTool.kt @@ -1,10 +1,6 @@ package org.move.ide.inspections -import com.intellij.codeInspection.LocalInspectionTool -import com.intellij.codeInspection.LocalInspectionToolSession -import com.intellij.codeInspection.LocalQuickFix -import com.intellij.codeInspection.LocalQuickFixOnPsiElement -import com.intellij.codeInspection.ProblemsHolder +import com.intellij.codeInspection.* import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement import com.intellij.psi.PsiElementVisitor diff --git a/src/main/kotlin/org/move/ide/inspections/MvUnusedAcquiresTypeInspection.kt b/src/main/kotlin/org/move/ide/inspections/MvUnusedAcquiresTypeInspection.kt index 703c4ec13..108008fdb 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvUnusedAcquiresTypeInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvUnusedAcquiresTypeInspection.kt @@ -12,7 +12,6 @@ import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.acquiresTys import org.move.lang.core.types.infer.inferTypeTy import org.move.lang.core.types.infer.inferenceCtx -import org.move.lang.core.types.ty.TyUnknown class MvUnusedAcquiresTypeInspection : MvLocalInspectionTool() { diff --git a/src/main/kotlin/org/move/ide/inspections/MvUnusedImportInspection.kt b/src/main/kotlin/org/move/ide/inspections/MvUnusedImportInspection.kt index ed468372f..83b576d6d 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvUnusedImportInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvUnusedImportInspection.kt @@ -6,7 +6,6 @@ import com.intellij.psi.PsiElement import com.intellij.psi.util.descendantsOfType import org.move.ide.inspections.imports.ItemUsages import org.move.ide.inspections.imports.ScopePathUsages -import org.move.ide.inspections.imports.importInfo import org.move.ide.inspections.imports.pathUsages import org.move.lang.core.psi.* import org.move.lang.core.psi.ext.ancestorStrict diff --git a/src/main/kotlin/org/move/ide/inspections/MvUnusedVariableInspection.kt b/src/main/kotlin/org/move/ide/inspections/MvUnusedVariableInspection.kt index 8953233ea..bd028ac15 100644 --- a/src/main/kotlin/org/move/ide/inspections/MvUnusedVariableInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/MvUnusedVariableInspection.kt @@ -6,8 +6,8 @@ import com.intellij.psi.util.descendantsOfType import org.move.ide.inspections.fixes.RemoveParameterFix import org.move.ide.inspections.fixes.RenameFix import org.move.lang.core.psi.* -import org.move.lang.core.psi.ext.owner import org.move.lang.core.psi.ext.functionLike +import org.move.lang.core.psi.ext.owner class MvUnusedVariableInspection : MvLocalInspectionTool() { override fun buildMvVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) = diff --git a/src/main/kotlin/org/move/ide/inspections/PhantomTypeParameterInspection.kt b/src/main/kotlin/org/move/ide/inspections/PhantomTypeParameterInspection.kt index ccb6a186f..b7c48a584 100644 --- a/src/main/kotlin/org/move/ide/inspections/PhantomTypeParameterInspection.kt +++ b/src/main/kotlin/org/move/ide/inspections/PhantomTypeParameterInspection.kt @@ -1,14 +1,13 @@ package org.move.ide.inspections import com.intellij.codeInspection.ProblemsHolder -import com.intellij.psi.util.childrenOfType -import com.intellij.psi.util.descendants import com.intellij.psi.util.descendantsOfType import org.move.ide.inspections.fixes.PhantomFix import org.move.lang.core.psi.* -import org.move.lang.core.psi.ext.* -import org.move.lang.core.types.infer.InferenceContext -import org.move.lang.core.types.infer.visitTyTypeParameterWith +import org.move.lang.core.psi.ext.fields +import org.move.lang.core.psi.ext.isPhantom +import org.move.lang.core.psi.ext.moveReference +import org.move.lang.core.psi.ext.typeArguments class PhantomTypeParameterInspection : MvLocalInspectionTool() { override fun buildMvVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): MvVisitor { diff --git a/src/main/kotlin/org/move/ide/inspections/fixes/RemoveParameterFix.kt b/src/main/kotlin/org/move/ide/inspections/fixes/RemoveParameterFix.kt index abd2600c5..ec78a12db 100644 --- a/src/main/kotlin/org/move/ide/inspections/fixes/RemoveParameterFix.kt +++ b/src/main/kotlin/org/move/ide/inspections/fixes/RemoveParameterFix.kt @@ -6,7 +6,6 @@ import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile import com.intellij.psi.util.parentOfType import org.move.lang.core.psi.* -import org.move.lang.core.psi.ext.callArgumentExprs import org.move.lang.core.psi.ext.valueArguments /** diff --git a/src/main/kotlin/org/move/ide/inspections/fixes/RenameFix.kt b/src/main/kotlin/org/move/ide/inspections/fixes/RenameFix.kt index d720a7f28..335120bf1 100644 --- a/src/main/kotlin/org/move/ide/inspections/fixes/RenameFix.kt +++ b/src/main/kotlin/org/move/ide/inspections/fixes/RenameFix.kt @@ -10,7 +10,6 @@ import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile import com.intellij.psi.PsiNamedElement -import com.intellij.refactoring.RefactoringFactory import org.move.lang.core.psi.MvNamedElement import org.move.lang.core.psi.rename import org.move.openapiext.nonBlocking diff --git a/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt b/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt index bdbece1cd..8a0b0e438 100644 --- a/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt +++ b/src/main/kotlin/org/move/lang/core/completion/LookupElements.kt @@ -13,8 +13,8 @@ import org.move.lang.core.resolve.ItemVis import org.move.lang.core.resolve.ref.Namespace import org.move.lang.core.types.infer.InferenceContext import org.move.lang.core.types.infer.containsTyOfClass -import org.move.lang.core.types.infer.ownerInferenceCtx import org.move.lang.core.types.infer.instantiateItemTy +import org.move.lang.core.types.infer.ownerInferenceCtx import org.move.lang.core.types.ty.Ty import org.move.lang.core.types.ty.TyFunction import org.move.lang.core.types.ty.TyInfer diff --git a/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider.kt b/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider.kt index 5ba2f8132..864c7e1bf 100644 --- a/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider.kt +++ b/src/main/kotlin/org/move/lang/core/completion/providers/MvPathCompletionProvider.kt @@ -21,8 +21,8 @@ import org.move.lang.core.resolve.ref.Namespace import org.move.lang.core.resolve.ref.Visibility import org.move.lang.core.resolve.ref.processModuleItems import org.move.lang.core.types.infer.InferenceContext -import org.move.lang.core.types.infer.ownerInferenceCtx import org.move.lang.core.types.infer.inferExpectedTy +import org.move.lang.core.types.infer.ownerInferenceCtx import org.move.lang.core.types.ty.Ty abstract class MvPathCompletionProvider : MvCompletionProvider() { diff --git a/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt b/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt index 7ee47c9b0..4c92f6588 100644 --- a/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt +++ b/src/main/kotlin/org/move/lang/core/psi/MvFunctionLike.kt @@ -1,7 +1,9 @@ package org.move.lang.core.psi import org.move.lang.MvElementTypes -import org.move.lang.core.psi.ext.* +import org.move.lang.core.psi.ext.MvDocAndAttributeOwner +import org.move.lang.core.psi.ext.declarationTypeTy +import org.move.lang.core.psi.ext.hasChild import org.move.lang.core.types.infer.InferenceContext import org.move.lang.core.types.infer.MvInferenceContextOwner import org.move.lang.core.types.infer.foldTyTypeParameterWith diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MoveExpr.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MoveExpr.kt index bbdbd4666..7b4aa1d78 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MoveExpr.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MoveExpr.kt @@ -1,8 +1,8 @@ package org.move.lang.core.psi.ext import org.move.lang.core.psi.MvExpr -import org.move.lang.core.types.infer.ownerInferenceCtx import org.move.lang.core.types.infer.inferExprTy +import org.move.lang.core.types.infer.ownerInferenceCtx import org.move.lang.core.types.ty.Ty fun MvExpr.inferredTy(): Ty { diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MoveStructLiteralField.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MoveStructLiteralField.kt index 2142d2ad8..50f34058c 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MoveStructLiteralField.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MoveStructLiteralField.kt @@ -5,15 +5,9 @@ import org.move.lang.MvElementTypes import org.move.lang.core.psi.MvElementImpl import org.move.lang.core.psi.MvStructLitExpr import org.move.lang.core.psi.MvStructLitField -import org.move.lang.core.psi.containingFunction import org.move.lang.core.resolve.ref.MvReference import org.move.lang.core.resolve.ref.MvStructFieldReferenceImpl import org.move.lang.core.resolve.ref.MvStructLitShorthandFieldReferenceImpl -import org.move.lang.core.types.infer.inferStructLitExpr -import org.move.lang.core.types.infer.inferenceCtx -import org.move.lang.core.types.ty.Ty -import org.move.lang.core.types.ty.TyStruct -import org.move.lang.core.types.ty.TyUnknown val MvStructLitField.structLitExpr: MvStructLitExpr get() = ancestorStrict()!! diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvBinaryExpr.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvBinaryExpr.kt index 92f136310..d5883e061 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvBinaryExpr.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvBinaryExpr.kt @@ -2,7 +2,6 @@ package org.move.lang.core.psi.ext import com.intellij.lang.ASTNode import org.move.lang.MvElementTypes.BINARY_OP -import org.move.lang.core.MOVE_BINARY_OPS import org.move.lang.core.psi.MvBinaryExpr import org.move.lang.core.psi.MvElementImpl diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpecFunctionParameter.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpecFunctionParameter.kt index 6fbdf2688..0ca4ebf44 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpecFunctionParameter.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpecFunctionParameter.kt @@ -3,11 +3,6 @@ package org.move.lang.core.psi.ext import com.intellij.lang.ASTNode import org.move.lang.core.psi.MvElementImpl import org.move.lang.core.psi.MvItemSpecFunctionParameter -import org.move.lang.core.psi.MvNamedElement -import org.move.lang.core.resolve.ref.MvReference -import org.move.lang.core.resolve.ref.MvReferenceCached -import org.move.lang.core.resolve.ref.Namespace -import org.move.lang.core.resolve.resolveSingleItem //class MvItemSpecFunctionParameterReferenceImpl( // element: MvItemSpecFunctionParameter diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpecTypeParameter.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpecTypeParameter.kt index 1488b2dd3..7fa74e92f 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpecTypeParameter.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvItemSpecTypeParameter.kt @@ -2,13 +2,7 @@ package org.move.lang.core.psi.ext import com.intellij.lang.ASTNode import org.move.lang.core.psi.MvElementImpl -import org.move.lang.core.psi.MvItemSpecFunctionParameter import org.move.lang.core.psi.MvItemSpecTypeParameter -import org.move.lang.core.psi.MvNamedElement -import org.move.lang.core.resolve.ref.MvReference -import org.move.lang.core.resolve.ref.MvReferenceCached -import org.move.lang.core.resolve.ref.Namespace -import org.move.lang.core.resolve.resolveSingleItem //class MvItemSpecTypeParameterReferenceImpl( // element: MvItemSpecTypeParameter diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvLetStatement.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvLetStatement.kt index 8ca77db7b..c56f4a02c 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvLetStatement.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvLetStatement.kt @@ -2,6 +2,5 @@ package org.move.lang.core.psi.ext import org.move.lang.MvElementTypes.POST import org.move.lang.core.psi.MvLetStmt -import org.move.lang.core.types.ty.Ty val MvLetStmt.isPost: Boolean get() = this.hasChild(POST) diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/MvSpecFunction.kt b/src/main/kotlin/org/move/lang/core/psi/ext/MvSpecFunction.kt index 2c552d5a2..628851d3e 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/MvSpecFunction.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/MvSpecFunction.kt @@ -2,11 +2,9 @@ package org.move.lang.core.psi.ext import com.intellij.lang.ASTNode import org.move.ide.MoveIcons -import org.move.lang.core.psi.MvBindingPat import org.move.lang.core.psi.MvSpecFunction import org.move.lang.core.psi.MvSpecInlineFunction import org.move.lang.core.psi.impl.MvNameIdentifierOwnerImpl -import org.move.lang.core.psi.parameters import javax.swing.Icon abstract class MvSpecFunctionMixin(node: ASTNode) : MvNameIdentifierOwnerImpl(node), diff --git a/src/main/kotlin/org/move/utils/tests/annotation/AnnotatorTestCase.kt b/src/main/kotlin/org/move/utils/tests/annotation/AnnotatorTestCase.kt index 2bdc6db1f..60734d14d 100644 --- a/src/main/kotlin/org/move/utils/tests/annotation/AnnotatorTestCase.kt +++ b/src/main/kotlin/org/move/utils/tests/annotation/AnnotatorTestCase.kt @@ -5,10 +5,8 @@ package org.move.utils.tests.annotation -import com.intellij.psi.PsiFile import org.intellij.lang.annotations.Language import org.move.ide.annotator.MvAnnotator -import org.move.utils.tests.replaceCaretMarker import kotlin.reflect.KClass abstract class AnnotatorTestCase( diff --git a/src/main/kotlin/org/move/utils/tests/types/TypificationTestCase.kt b/src/main/kotlin/org/move/utils/tests/types/TypificationTestCase.kt index 8c601933d..6b64f0782 100644 --- a/src/main/kotlin/org/move/utils/tests/types/TypificationTestCase.kt +++ b/src/main/kotlin/org/move/utils/tests/types/TypificationTestCase.kt @@ -8,8 +8,8 @@ import org.move.lang.core.psi.MvExpr import org.move.lang.core.psi.MvType import org.move.lang.core.psi.ext.inferredTy import org.move.lang.core.psi.ext.isMsl -import org.move.lang.core.types.infer.ownerInferenceCtx import org.move.lang.core.types.infer.inferExpectedTy +import org.move.lang.core.types.infer.ownerInferenceCtx import org.move.utils.tests.InlineFile import org.move.utils.tests.MvTestBase import org.move.utils.tests.base.findElementAndDataInEditor From 1192449b27e7842804b0758f86cdad47292412bd Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Tue, 27 Sep 2022 15:40:55 +0200 Subject: [PATCH 26/26] improve changelog --- changelog/1.20.0.md | 14 ++++++-------- changelog/static/hex_int.png | Bin 0 -> 13385 bytes changelog/static/remove_param.gif | Bin 0 -> 31740 bytes gradle.properties | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) create mode 100644 changelog/static/hex_int.png create mode 100644 changelog/static/remove_param.gif diff --git a/changelog/1.20.0.md b/changelog/1.20.0.md index 9f6f7e872..39df7898d 100644 --- a/changelog/1.20.0.md +++ b/changelog/1.20.0.md @@ -1,30 +1,30 @@ # INTELLIJ MOVE CHANGELOG: 1.20.0 -TBD +27 Sep 2022 ## New Features -* Remove parameter quickfix +* Remove parameter quickfix -TODO: gif +![remove_param](./static/remove_param.gif) * Highlight hex integer literals -TODO: screenshot +![hex_int](./static/hex_int.png) * Sort completion in borrow exprs. * Sort completions by abilities in type parameters. * Support for imports inside code blocks. - + * Allow repeating function signature in spec for readability. * Type inference support for vector literals. * Type check calls with not enough arguments. -* Type inference for `loop {}` expr. +* Type inference for statements in `loop {}` expr. ## Fixes @@ -35,5 +35,3 @@ TODO: screenshot * Fix "unused parameter" error on native functions. * Fix struct unpacking type inference. - -## Internal diff --git a/changelog/static/hex_int.png b/changelog/static/hex_int.png new file mode 100644 index 0000000000000000000000000000000000000000..c1fa211cff35be134663f46caaf286da77bb843b GIT binary patch literal 13385 zcmeHtXH-*9w>QdP5D*X)kS++)LArG50@6$9ks=78NC`E7iiq^yo6>uv_n;K%O$ebQ zCG?umLLj{HdET||^RBz@r}yhUA5NPyb7uDJnZ19%y(9E=)X7O1NC^lC$TeQ77!VNL z2IKF~@7~6rPdvpj1O#IDHB=Oh{H*sEiA^7DvJxNded0Ojr~-qmuIEiGeBl%pG_I~y z=2dg$Rd90}s;+l`Se|>h_sYHdkpD+5zUVPy0;kA7_MC?|f+Y6^LmzY9z7Eb^UQ<3; zvOEyn3_>rxd`|Dqd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)!$n~YTmrwHYHQ!3q2qR?Xyu?@%IGC~a zHxTfibOi9Gnb$7m5)jz4!TC>szoqP3$$Xx?<$!8m7B5)>eBc1!fhlLH)|7sdni}F8 zZ1JIV`SLCOUs=5<0w`iK)6@I!0yr0`ERMYW-M@WrQ+^!$lL+5*?!O|PQ-A)vc4gBn z_-ttRMnp})I0MQ$OZ+dv?Ua3iX!GrVW^%P7Q!>%R%#Bd|T?WQ_MI!+Jh13tW!IK#X zuZ+JbZM+?tS@ml!4h4pX4UZ>k1ppm7%iJVq&fj((taiDx=i!DK1$g=Lc50?UPYx#|q#jl`PZ0FYUnKnfZzQi3 zEb*$4>-+$75zcA9+K<;XBjXgIzZy_3|39tw|1J3M8IS)fEBx~Kf0ID}|3rdSP*YM^ V@tCw=#y3o$p{k=&t@Qfi{{amX)cF7a literal 0 HcmV?d00001 diff --git a/changelog/static/remove_param.gif b/changelog/static/remove_param.gif new file mode 100644 index 0000000000000000000000000000000000000000..31861618abee7fde3b20206bd85bd5688d2d7aa0 GIT binary patch literal 31740 zcmeF2Wl&sE_}+Jy1(rn?4Xz=$OK^85I3y%Ma0mfH65L%ENpM))-QC0DBtVeh?oM#F z`FEz%PCs-yZKoePeLmegcjmqKyl0*>=brcXDyb+6i&V0s61bS`wrBRab`CXfVz7Y|_`!h(`O zh5WI}1hEjE5B@ssnkxoAG3o%lVKdD76xe1B_j7}+K zOKCg(!mXF-a~JdHF4oUoY@UN0zH?kec-;6;+=36hjz9UeZ3Uz(1ZiP{FNa@ZfP_N- z2&4N8b1{kNmy4#Xi4zBln-7ZnbV+{vE<^c2!8}SSeOCp`Uk!1ofdkUeP}lYM$fT|) zOPy#Z!|33^IBSWx)SLt<%*55lq|)|p_D0{n!IS4UQ%4_DM^S0Iv6-z)S*nn%tgM{u zjGU6PoYC#P=)nAgr-DCs#r_s0O?RdLS!IT}Wm)YN?E{syO;r|8RoAGx>$?W?h{mCn zCQI_Bs=TJArj|snwuS9>yXf}I^^R!MuE><`!nmHE-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KaurnOrPeW{bw7QIV1V3jl}z#?AldiunLo=&G_%Xb&lx26xk#39E_N}DMdjzJ@W&6CA54o5R9MVO$!{UG^YSS>0NHGl#@ z{G5VL0T}pR&nc+qIm(22C7UNAf(jj}+vj-O zmy1~32gCsY(l1Z}@3KDD=*41qUk^Qy#!7bldxLW0+12&!KfbQ$SI_$o`;YxUr(j5a z5;BlYQgrrf{$M1@uCBqs56zC}rpaLcbIYcK0l!meUNg#UG?jE0Y5ejvN@)t0D?f++ zwlUC>KlRz9Qc21cdi^nv?en$Q^Tz7RgsEUA-8S$85gDq}>`wxwyCV)#~jP zuMwxiXejVAN!}6vfjqLLR7BOhj#Lv>h5pEyKe|$Z)%!l!`6yqx{zZwJ8FO5#tTk8vn^)|Ywy?1|vr8$Zw zvP~LX;M6$&+L;th*v6kN7D0U6h~P78abdw&X4oGjsC6-LcQk##vs(`P1$RFsdE=nc zWPg658{v7r*=_iMO!Hab&2~TQPkOVe_=NXEajXX~iDT{dMjY5Bx}sLNY(^p^f^Ik{ zoR4NhADZOE(oR1v`smicp7i<7*IHapHz(VhfBZuop;f19DcFsO_#vBP;;nKpmCGI> z+avQUd8DRZG$#y7c+Of+#D5DgE4;lrh%Mam@_&-MxZr7uedjFh7e4(%Th$Wb{{<1@ zR{Gu#30INM9klc3{pUNTwD*$#*7E)*lz0HN=TI^OT>r61g?B%nC>q8djr{&E*chTZ YWX|S&5$Kd!Rb-kwgJJ)-^QOrE0QjtG0{{R3 literal 0 HcmV?d00001 diff --git a/gradle.properties b/gradle.properties index 17a5c7cfd..163aa24eb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,4 +14,4 @@ propertiesPluginEnvironmentNameProperty=shortPlatformVersion # properties files # supported versions are 212, 213, 221, 222, default is 212 # pass ORG_GRADLE_PROJECT_shortPlatformVersion environment variable to overwrite -shortPlatformVersion=213 +shortPlatformVersion=222