File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -221,14 +221,20 @@ class IntermediateEmitter {
221221 // emits class cast checks
222222 void EmitClassCast (Expression* expression) {
223223 // class cast
224- if (expression->GetToClass ()) {
224+ if (expression->GetToClass () &&
225+ !(expression->GetExpressionType () == METHOD_CALL_EXPR &&
226+ static_cast <MethodCall*>(expression)->GetCallType () == NEW_ARRAY_CALL &&
227+ expression->GetToClass ()->IsInterface ())) {
225228 if (is_lib) {
226229 imm_block->AddInstruction (IntermediateFactory::Instance ()->MakeInstruction (cur_line_num, LIB_OBJ_INST_CAST , expression->GetToClass ()->GetName ()));
227230 } else {
228231 imm_block->AddInstruction (IntermediateFactory::Instance ()->MakeInstruction (cur_line_num, OBJ_INST_CAST , expression->GetToClass ()->GetId ()));
229232 }
230233 }
231- else if (expression->GetToLibraryClass ()) {
234+ else if (expression->GetToLibraryClass () &&
235+ !(expression->GetExpressionType () == METHOD_CALL_EXPR &&
236+ static_cast <MethodCall*>(expression)->GetCallType () == NEW_ARRAY_CALL &&
237+ expression->GetToLibraryClass ()->IsInterface ())) {
232238 if (is_lib) {
233239 imm_block->AddInstruction (IntermediateFactory::Instance ()->MakeInstruction (cur_line_num, LIB_OBJ_INST_CAST , expression->GetToLibraryClass ()->GetName ()));
234240 } else {
Original file line number Diff line number Diff line change 1- use System.IO.File;
2- use System.IO;
3-
4- class Thingy {
5- @id : Int;
6-
7- New(id : Int) {
8- @id := id;
9- }
10-
11- method : public : Print() ~ Nil {
12- @id->PrintLine();
13- }
14- }
15-
16- class Person from Thingy {
17- @name : String;
18-
19- New(id : Int, name : String) {
20- Parent(id);
21- @name := name;
22- }
23-
24- method : public : Print() ~ Nil {
25- @id->PrintLine();
26- @name->PrintLine();
27- }
28- }
29-
30- class Serial {
1+ class Test {
312 function : Main(args : String[]) ~ Nil {
32- t := Thingy->New(7);
33- p := Person->New(13, "Bush");
34-
35- s := Serializer->New();
36- s->Write(t->As(Base));
37- s->Write(p->As(Base));
38-
39- writer := FileWriter->New("objects.dat");
40- writer->WriteBuffer(s->Serialize());
41- writer->Close();
42-
43- buffer := FileReader->ReadBinaryFile("objects.dat");
44- d := Deserializer->New(buffer);
45-
46- t2 := d->ReadObject()->As(Thingy);
47- t2->Print();
48- p2 := d->ReadObject()->As(Person);
49- p2->Print();
3+ # cc := String->New[3];
4+ cc := Compare->New[3];
5+ cc[0] := "fee";
6+ cc[1] := "fie";
7+ cc[2] := "fum";
508
51- writer := FileWriter->New("foo.txt");
52- writer->WriteBuffer(2, 3, "Καλημέρα κόσμε\r\n"->ToCharArray());
53- writer->WriteBuffer("\r\nこんにちは 世界\r\n"->ToCharArray());
54- writer->Close();
9+ c := cc[1]->As(String);
10+ c->PrintLine();
5511 }
5612 }
You can’t perform that action at this time.
0 commit comments