Oberon Community Platform Forum

Development => ETH Zonnon => Topic started by: GDC on January 24, 2015, 02:23:50 AM



Title: 'is' operation
Post by: GDC on January 24, 2015, 02:23:50 AM
The following code works just fine:
Code:
definition Piece;
end Piece.

object {ref} Pawn implements Piece;
end Pawn.

object {ref} King implements Piece;
end King.

module Bug;
import
 System.Console as Console,
 Piece,Pawn,King;
var
 p:object{Piece};
begin
 p:=new Pawn;
 if p is Pawn then Console.WriteLine("Piece is Pawn") end;
 if p is King then Console.WriteLine("Piece is King") end;
 Console.ReadKey();
end Bug

But this code doesn't
Code:
module Def;
definition Piece;
 end Piece;
type {ref,public}
 Pawn=object implements Piece
  end Pawn;
 King=object implements Piece
  end King;
end Def.

module Bug;
import
 System.Console as Console,
 Def;
var
 p:object{Def.Piece};
begin
 p:=new Def.Pawn;
 if p is Def.Pawn then Console.WriteLine("Piece is Pawn") end;
 if p is Def.King then Console.WriteLine("Piece is King") end;
 Console.ReadKey();
end Bug.

In the last example, the 'is' operation seems to be always true, regardless of what type p is.

What am I missing ?