@@ -11,6 +11,7 @@ import top.mcfpp.exception.*
11
11
import top.mcfpp.io.MCFPPFile
12
12
import top.mcfpp.lang.*
13
13
import top.mcfpp.lang.type.MCFPPBaseType
14
+ import top.mcfpp.lang.type.MCFPPEnumType
14
15
import top.mcfpp.lang.type.MCFPPGenericClassType
15
16
import top.mcfpp.lang.type.MCFPPType
16
17
import top.mcfpp.lang.value.MCFPPValue
@@ -165,7 +166,7 @@ open class McfppImVisitor: mcfppParserBaseVisitor<Any?>() {
165
166
Function .addCommand(" #field: " + ctx.type().text + " " + c.Identifier ().text + if (c.expression() != null ) " = " + c.expression().text else " " )
166
167
// 变量初始化
167
168
if (c.expression() != null ) {
168
- val init : Var <* > = McfppExprVisitor (if (type is MCFPPGenericClassType ) type else null ).visit(c.expression())!!
169
+ val init : Var <* > = McfppExprVisitor (if (type is MCFPPGenericClassType ) type else null , if (type is MCFPPEnumType ) type else null ).visit(c.expression())!!
169
170
try {
170
171
`var ` = `var `.assign(init )
171
172
} catch (e: VariableConverseException ) {
@@ -203,13 +204,14 @@ open class McfppImVisitor: mcfppParserBaseVisitor<Any?>() {
203
204
override fun visitStatementExpression (ctx : mcfppParser.StatementExpressionContext ):Any? {
204
205
Project .ctx = ctx
205
206
Function .addCommand(" #expression: " + ctx.text)
206
- val right: Var <* > = McfppExprVisitor ().visit(ctx.expression())!!
207
207
if (ctx.basicExpression() != null ){
208
208
val left: Var <* > = McfppLeftExprVisitor ().visit(ctx.basicExpression())!!
209
209
if (left.isConst) {
210
210
LogProcessor .error(" Cannot assign a constant repeatedly: " + left.identifier)
211
211
return null
212
212
}
213
+ val type = left.type
214
+ val right: Var <* > = McfppExprVisitor (if (type is MCFPPGenericClassType ) type else null , if (type is MCFPPEnumType ) type else null ).visit(ctx.expression())!!
213
215
try {
214
216
left.replacedBy(left.assign(right))
215
217
} catch (e: VariableConverseException ) {
0 commit comments