From 73bcc80463184f1e5fea1f16874d88e8cfc79e68 Mon Sep 17 00:00:00 2001 From: Jonathan Worthington Date: Mon, 11 Jan 2010 23:07:50 +0100 Subject: [PATCH] Get type checking on scalar assignments working again. --- src/builtins/Mu.pir | 20 +++++++++++++++++++- src/core/traits.pm | 7 ++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/builtins/Mu.pir b/src/builtins/Mu.pir index 8527a2828f1..91b75f60a2c 100644 --- a/src/builtins/Mu.pir +++ b/src/builtins/Mu.pir @@ -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 @@ -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 diff --git a/src/core/traits.pm b/src/core/traits.pm index c802574602c..182d7552667 100644 --- a/src/core/traits.pm +++ b/src/core/traits.pm @@ -5,7 +5,12 @@ our multi trait_mod:(Mu $child, Mu $parent) { } our multi trait_mod:(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:(Mu $target, Role $r) {