diff --git a/ast-psi/src/main/kotlin/kastree/ast/psi/Converter.kt b/ast-psi/src/main/kotlin/kastree/ast/psi/Converter.kt index e974e67..1393586 100644 --- a/ast-psi/src/main/kotlin/kastree/ast/psi/Converter.kt +++ b/ast-psi/src/main/kotlin/kastree/ast/psi/Converter.kt @@ -279,8 +279,8 @@ open class Converter { is KtCallExpression -> convertCall(v) is KtArrayAccessExpression -> convertArrayAccess(v) is KtNamedFunction -> convertAnonFunc(v) - // TODO: this can happen when a labeled expression uses a var decl as the expression - is KtProperty -> throw Unsupported("Property expressions not supported") + is KtProperty -> convertPropertyExpr(v) + is KtDestructuringDeclaration -> convertPropertyExpr(v) // TODO: this is present in a recovery test where an interface decl is on rhs of a gt expr is KtClass -> throw Unsupported("Class expressions not supported") else -> error("Unrecognized expression type from $v") @@ -450,6 +450,14 @@ open class Converter { body = v.bodyExpression?.let(::convertFuncBody) ).map(v) + open fun convertPropertyExpr(v: KtDestructuringDeclaration) = Node.Expr.Property( + decl = convertProperty(v) + ).map(v) + + open fun convertPropertyExpr(v: KtProperty) = Node.Expr.Property( + decl = convertProperty(v) + ).map(v) + open fun convertPropertyVar(v: KtDestructuringDeclarationEntry) = if (v.name == "_") null else Node.Decl.Property.Var( name = v.name ?: error("No property name on $v"), diff --git a/ast/ast-common/src/main/kotlin/kastree/ast/MutableVisitor.kt b/ast/ast-common/src/main/kotlin/kastree/ast/MutableVisitor.kt index 276d1ff..8824065 100644 --- a/ast/ast-common/src/main/kotlin/kastree/ast/MutableVisitor.kt +++ b/ast/ast-common/src/main/kotlin/kastree/ast/MutableVisitor.kt @@ -287,6 +287,9 @@ open class MutableVisitor { is Node.Expr.AnonFunc -> copy( func = visitChildren(func, newCh) ) + is Node.Expr.Property -> copy( + decl = visitChildren(decl, newCh) + ) is Node.Block -> copy( stmts = visitChildren(stmts, newCh) ) diff --git a/ast/ast-common/src/main/kotlin/kastree/ast/Node.kt b/ast/ast-common/src/main/kotlin/kastree/ast/Node.kt index a77d979..63d61f4 100644 --- a/ast/ast-common/src/main/kotlin/kastree/ast/Node.kt +++ b/ast/ast-common/src/main/kotlin/kastree/ast/Node.kt @@ -407,6 +407,10 @@ sealed class Node { data class AnonFunc( val func: Decl.Func ) : Expr() + // This is only present for when expressions and labeled expressions + data class Property( + val decl: Decl.Property + ) : Expr() } data class Block(val stmts: List) : Node() diff --git a/ast/ast-common/src/main/kotlin/kastree/ast/Visitor.kt b/ast/ast-common/src/main/kotlin/kastree/ast/Visitor.kt index f61dd39..369f4a4 100644 --- a/ast/ast-common/src/main/kotlin/kastree/ast/Visitor.kt +++ b/ast/ast-common/src/main/kotlin/kastree/ast/Visitor.kt @@ -283,6 +283,9 @@ open class Visitor { is Node.Expr.AnonFunc -> { visitChildren(func) } + is Node.Expr.Property -> { + visitChildren(decl) + } is Node.Block -> { visitChildren(stmts) } diff --git a/ast/ast-common/src/main/kotlin/kastree/ast/Writer.kt b/ast/ast-common/src/main/kotlin/kastree/ast/Writer.kt index fb99de2..e9f6b7a 100644 --- a/ast/ast-common/src/main/kotlin/kastree/ast/Writer.kt +++ b/ast/ast-common/src/main/kotlin/kastree/ast/Writer.kt @@ -382,6 +382,8 @@ open class Writer( } is Node.Expr.AnonFunc -> children(func) + is Node.Expr.Property -> + children(decl) is Node.Block -> { // Special case, no braces if the parent is a brace if (parent is Node.Expr.Brace) { diff --git a/build.gradle b/build.gradle index 9f9f2bc..1d67fe9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.3.0' + ext.kotlin_version = '1.3.10' repositories { mavenCentral()