Skip to content

Commit ab2fb8c

Browse files
committed
Merge pull request #2772 from JakubValtar/preproc-constructorCast-fix
Fixes #1936 - Preproc constructor cast fix
2 parents e6c9019 + b848168 commit ab2fb8c

5 files changed

Lines changed: 40 additions & 4 deletions

File tree

app/src/processing/mode/java/preproc/pde.g

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,14 @@ constructorCast!
194194
// if this is a string literal, make sure the type we're trying to cast
195195
// to is one of the supported ones
196196
//
197-
{ #e.getType() != STRING_LITERAL ||
198-
( #t.getType() == LITERAL_byte ||
197+
{ (#e == null) ||
198+
( (#e.getType() != STRING_LITERAL) ||
199+
( #t.getType() == LITERAL_boolean ||
199200
#t.getType() == LITERAL_double ||
200201
#t.getType() == LITERAL_float ||
201202
#t.getType() == LITERAL_int ||
202203
#t.getType() == LITERAL_long ||
203-
#t.getType() == LITERAL_short ) }?
204+
#t.getType() == LITERAL_short )) }?
204205
// create the node
205206
//
206207
{#constructorCast = #(#[CONSTRUCTOR_CAST,"CONSTRUCTOR_CAST"], t, e);}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import processing.core.*;
2+
import processing.data.*;
3+
import processing.event.*;
4+
import processing.opengl.*;
5+
6+
import java.util.HashMap;
7+
import java.util.ArrayList;
8+
import java.io.File;
9+
import java.io.BufferedReader;
10+
import java.io.PrintWriter;
11+
import java.io.InputStream;
12+
import java.io.OutputStream;
13+
import java.io.IOException;
14+
15+
public class bug1936 extends PApplet {
16+
public void setup() {
17+
char a = PApplet.parseChar(PApplet.parseByte(PApplet.parseInt("15")));
18+
noLoop();
19+
}
20+
21+
static public void main(String[] passedArgs) {
22+
String[] appletArgs = new String[] { "bug1936" };
23+
if (passedArgs != null) {
24+
PApplet.main(concat(appletArgs, passedArgs));
25+
} else {
26+
PApplet.main(appletArgs);
27+
}
28+
}
29+
}

app/test/resources/bug1936.pde

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
char a = char(byte(int("15")));

app/test/src/test/processing/mode/java/ParserTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ public void bug1532() {
276276
public void bug1534() {
277277
expectGood("bug1534");
278278
}
279+
280+
@Test
281+
public void bug1936() {
282+
expectGood("bug1936");
283+
}
279284

280285
@Test
281286
public void bug315g() {

core/src/processing/core/PApplet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9635,7 +9635,7 @@ static final public float[] parseFloat(char what[]) {
96359635
}
96369636
*/
96379637

9638-
static final public float[] parseByte(byte what[]) {
9638+
static final public float[] parseFloat(byte what[]) {
96399639
float floaties[] = new float[what.length];
96409640
for (int i = 0; i < what.length; i++) {
96419641
floaties[i] = what[i];

0 commit comments

Comments
 (0)