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(targetType.istype(DataType.STRUCT) && (valueType.istype(DataType.STRUCT) || valueType.typeOrElse(DataType.STRUCT) in ArrayDatatypes )) { | ||||||
|             if (assignment.value is ArrayLiteralValue) { |             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 { |             } else { | ||||||
|                 return copyStructValue(assignment) |                 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(targetType.typeOrElse(DataType.STRUCT) in ArrayDatatypes && valueType.typeOrElse(DataType.STRUCT) in ArrayDatatypes ) { | ||||||
|             if (assignment.value is ArrayLiteralValue) { |             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 { |             } else { | ||||||
|                 return copyArrayValue(assignment) |                 return copyArrayValue(assignment) | ||||||
|             } |             } | ||||||
|   | |||||||
| @@ -256,7 +256,14 @@ open class VarDecl(val type: VarDeclType, | |||||||
|     fun flattenStructMembers(): MutableList<Statement> { |     fun flattenStructMembers(): MutableList<Statement> { | ||||||
|         val result = struct!!.statements.mapIndexed { index, statement -> |         val result = struct!!.statements.mapIndexed { index, statement -> | ||||||
|             val member = statement as VarDecl |             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( |             VarDecl( | ||||||
|                     VarDeclType.VAR, |                     VarDeclType.VAR, | ||||||
|                     member.datatype, |                     member.datatype, | ||||||
|   | |||||||
| @@ -3,12 +3,28 @@ | |||||||
|  |  | ||||||
| main { | main { | ||||||
|     sub start() { |     sub start() { | ||||||
|         txt.print("✓✓✓✓✓") |         const ubyte world_width=100 | ||||||
|         txt.nl() |  | ||||||
|         txt.print("WWWWW") |     struct Color { | ||||||
|         txt.nl() |         ubyte red | ||||||
|         txt.print("●●●●●") |         ubyte green | ||||||
|         txt.nl() |         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