mirror of
				https://github.com/irmen/prog8.git
				synced 2025-10-31 00:16:08 +00:00 
			
		
		
		
	fix compiler crash for some struct/array initialization assignment literals containing not just numbers
This commit is contained in:
		| @@ -224,7 +224,7 @@ internal class StatementReorderer(val program: Program, val errors: IErrorReport | ||||
|  | ||||
|         if(targetType.istype(DataType.STRUCT) && (valueType.istype(DataType.STRUCT) || valueType.typeOrElse(DataType.STRUCT) in ArrayDatatypes )) { | ||||
|             if (assignment.value is ArrayLiteralValue) { | ||||
|                 errors.err("cannot assign non-const array value, use separate assignment per field", assignment.position) | ||||
|                 errors.err("cannot assign array literal here, use separate assignment per field", assignment.position) | ||||
|             } else { | ||||
|                 return copyStructValue(assignment) | ||||
|             } | ||||
| @@ -232,7 +232,7 @@ internal class StatementReorderer(val program: Program, val errors: IErrorReport | ||||
|  | ||||
|         if(targetType.typeOrElse(DataType.STRUCT) in ArrayDatatypes && valueType.typeOrElse(DataType.STRUCT) in ArrayDatatypes ) { | ||||
|             if (assignment.value is ArrayLiteralValue) { | ||||
|                 errors.err("cannot assign non-const array value, use separate assignment per element", assignment.position) | ||||
|                 errors.err("cannot assign array literal here, use separate assignment per element", assignment.position) | ||||
|             } else { | ||||
|                 return copyArrayValue(assignment) | ||||
|             } | ||||
|   | ||||
| @@ -256,7 +256,14 @@ open class VarDecl(val type: VarDeclType, | ||||
|     fun flattenStructMembers(): MutableList<Statement> { | ||||
|         val result = struct!!.statements.mapIndexed { index, statement -> | ||||
|             val member = statement as VarDecl | ||||
|             val initvalue = if(value!=null) (value as ArrayLiteralValue).value[index] else null | ||||
|             val initvalueOrig = if(value!=null) (value as ArrayLiteralValue).value[index] else null | ||||
|             val initvalue = when(initvalueOrig) { | ||||
|                 is AddressOf -> initvalueOrig.copy() | ||||
|                 is ArrayIndexedExpression -> initvalueOrig.copy() | ||||
|                 is DirectMemoryRead -> initvalueOrig.copy() | ||||
|                 is IdentifierReference -> initvalueOrig.copy() | ||||
|                 else -> initvalueOrig | ||||
|             } | ||||
|             VarDecl( | ||||
|                     VarDeclType.VAR, | ||||
|                     member.datatype, | ||||
|   | ||||
| @@ -3,12 +3,28 @@ | ||||
|  | ||||
| main { | ||||
|     sub start() { | ||||
|         txt.print("✓✓✓✓✓") | ||||
|         txt.nl() | ||||
|         txt.print("WWWWW") | ||||
|         txt.nl() | ||||
|         txt.print("●●●●●") | ||||
|         txt.nl() | ||||
|         const ubyte world_width=100 | ||||
|  | ||||
|     struct Color { | ||||
|         ubyte red | ||||
|         ubyte green | ||||
|         ubyte blue | ||||
|     } | ||||
|  | ||||
|     Color rgb = [255,world_width,0]     ; note that struct initializer value is same as an array | ||||
|     ;rgb = [255,world_width,0]     ; note that struct initializer value is same as an array | ||||
|     ;rgb = [255,world_width/2,0]     ; note that struct initializer value is same as an array | ||||
|  | ||||
|  | ||||
| ;        struct Entity { | ||||
| ;            ubyte active | ||||
| ;            ubyte x | ||||
| ;            ubyte y | ||||
| ;            byte direction | ||||
| ;        } | ||||
| ; | ||||
| ;        Entity pede | ||||
| ;        pede = [1, 1, 0, -1] | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user