Skip to content

Commit

Permalink
Get type checking on scalar assignments working again.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Jan 11, 2010
1 parent cc5d534 commit 73bcc80
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
20 changes: 19 additions & 1 deletion src/builtins/Mu.pir
Expand Up @@ -387,6 +387,8 @@ in the future.)
.sub '!STORE' :method :subid('Object::!STORE')
.param pmc source
# Get hold of the source object to assign.
$I0 = can source, '!FETCH'
if $I0 goto source_fetch
source = deobjectref source
Expand All @@ -396,11 +398,27 @@ in the future.)
source = source.'!FETCH'()
source = deobjectref source
have_source:
# If source and destination are the same, we're done.
eq_addr self, source, store_done

# Need a type-check?
.local pmc type
type = getprop 'type', self
if null type goto type_check_done
$I0 = type.'ACCEPTS'(source)
unless $I0 goto type_check_failed

# All is well - do the assignment.
type_check_done:
copy self, source
# .fixup_cloned_sub(source, self)

store_done:
.return (self)

type_check_failed:
# XXX TODO: Awesomize this error.
'&die'('Type check failed for assignment')
.end


Expand Down
7 changes: 6 additions & 1 deletion src/core/traits.pm
Expand Up @@ -5,7 +5,12 @@ our multi trait_mod:<is>(Mu $child, Mu $parent) {
}

our multi trait_mod:<of>(ContainerDeclarand $cont, Mu \$type) {

given substr($cont.name, 0, 1) {
when '@' { }
when '%' { }
when '&' { }
default { pir::setprop__vPSP($cont.container, 'type', $type) }
}
}

our multi trait_mod:<does>(Mu $target, Role $r) {
Expand Down

0 comments on commit 73bcc80

Please sign in to comment.