0

I am having a problem comparing two objects in a HASH_TABLE

PERSON is a class with attributes such as name, b-day, status of relationship, spouse name, spouse id. So basically composed of attributes code:

list: HASH_TABLE[PERSON, INTEGER_64]

put(id1, id2: INTEGER_64)
local
   p1, p2: PERSON
do
   p1 := model.list.at(id)
      -- or 
   p1 := model.list.search(id)
   p1 := model.list.found_item -- same error as below
end

error: Source of assignment is not compatible with target.

THE FEATURES USED RETURN "DETACHABLE G"

I think I should be doing "if attached" to ensure item feature returns the correct object type and then assign? I'm not exactly sure how to cast the object though.

The error is triggered by calling above feature

The reason i need these functions to work is that I can sort easier

geforce
  • 61
  • 6
  • Compiler usually gives some information about error position (with a text context in command-line version and a possibility to double-click and jump to the error in IDE). The snippet you show has no assignments, so it's hard to guess what's wrong. Can you show the error context? My feeling you need to show the feature `item`. – Alexander Kogtenkov Feb 08 '16 at 03:43
  • item(key k) returns a PERSON at id K where i can take the attribute name of that PERSON – geforce Feb 08 '16 at 04:27
  • I also edited to make it more simple to understand – geforce Feb 08 '16 at 04:39

1 Answers1

2

The features return detachable G because it is possible that no element is found. Therefore you need to use object tests, e.g.

if
   attached model.list [id1] as p1 and then
   attached model.list [id2] as p2
then
   ... -- use p1 and p2
end
Alexander Kogtenkov
  • 5,770
  • 1
  • 27
  • 35