Oberon Community Platform Forum
September 23, 2017, 08:22:06 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: 'is' operation  (Read 1243 times)
GDC
Newbie
*
Posts: 7


« 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 ?
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!