[Fixed] ZScript 2D array assignment and access orders swapped?

Bugs that have been investigated and resolved somehow.

Moderator: Developers

ZScript 2D array assignment and access orders swapped?

Postby Nash » Thu May 18, 2017 3:52 am

Mikk- wrote:Okay stupid question but can 2D arrays not have a larger second dimension than the first dimension?
Say for example I have an array defined as test[8][11] - if I then assign index [1][9] I get an out of bounds error..? but if I assign index[1][7] I do not get an error, which is rather strange...
Code: Select allExpand view
class c_arraytest : actor
    
{
    
    int c_testarray
[8][11];
    
    override void postbeginplay
()
        {
        super.postbeginplay();
        
        c_testarray
[1][9] = 1;
        }
    }



Gutawer wrote:It's kinda weird, but the assignment order for the dimensions and the access order are actually swapped around, you probably want int c_testarray[11][8] instead. That little problem had me annoyed for at least half and hour when I ran into it, lol.
User avatar
Nash
Nash Muhandes
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia

Re: ZScript 2D array assignment and access orders swapped?

Postby Major Cooke » Wed May 24, 2017 2:03 pm

If this is true, I better go back through D4D and untangle any multi-dimensional arrays immediately or there will be hell to pay when fixed.
User avatar
Major Cooke
The road to Hell is paved in the carrion she leaves behind.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: ZScript 2D array assignment and access orders swapped?

Postby Graf Zahl » Wed May 24, 2017 2:57 pm

If this gets addressed it needs to be versioned. But of course with D4D that can be a problem, if it sees continued development...
User avatar
Graf Zahl
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: ZScript 2D array assignment and access orders swapped?

Postby Major Cooke » Wed May 24, 2017 3:04 pm

We've already broken D4D over multiple versions. I don't mind it.

At any rate, I don't think there are any multi-dimensional arrays being used zscript wise with D4D so far...
User avatar
Major Cooke
The road to Hell is paved in the carrion she leaves behind.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: ZScript 2D array assignment and access orders swapped?

Postby phantombeta » Tue Jan 08, 2019 9:49 am

PR link. Versioned, obviously. Fixes array definitions for version 3.8.0 and above
Was actually pretty easy to fix.
User avatar
phantombeta
In the meadow of sinful thoughts, every flower's a perfect one
 
Joined: 02 May 2013
Location: The United Soviet Socialist Dictatorship of Hueland
Discord: phantombeta#2461
Twitch ID: phantombeta_

Re: ZScript 2D array assignment and access orders swapped?

Postby Graf Zahl » Tue Jan 08, 2019 9:56 am

Heh. I was thinking about convoluted approaches on a later stage, I actually never thought about brute-force altering the parser's output on the AST level...
It should still use std::move to assign the swapped array (or swap in-place.)

This should also be versioned 3.7.2, I think, so it can be in the next point release.
User avatar
Graf Zahl
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: ZScript 2D array assignment and access orders swapped?

Postby phantombeta » Tue Jan 08, 2019 10:42 am

Graf Zahl wrote:Heh. I was thinking about convoluted approaches on a later stage, I actually never thought about brute-force altering the parser's output on the AST level...

Sometimes a naive approach can be the best one. :P
It should still use std::move to assign the swapped array (or swap in-place.)

This should also be versioned 3.7.2, I think, so it can be in the next point release.

Done and done.
User avatar
phantombeta
In the meadow of sinful thoughts, every flower's a perfect one
 
Joined: 02 May 2013
Location: The United Soviet Socialist Dictatorship of Hueland
Discord: phantombeta#2461
Twitch ID: phantombeta_


Return to Closed Bugs

Who is online

Users browsing this forum: thugsta and 2 guests