From b4e198bb23eb53f486f95530e1248d5b454c6c1e Mon Sep 17 00:00:00 2001 From: Kathy Gray Date: Wed, 14 Jun 2006 17:53:56 +0000 Subject: [PATCH] Adding check of not setting already initied field in beginner svn: r3359 --- collects/profj/check.ss | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/collects/profj/check.ss b/collects/profj/check.ss index 89c2a260d6..251685c4b7 100644 --- a/collects/profj/check.ss +++ b/collects/profj/check.ss @@ -2613,6 +2613,11 @@ (rtype (type/env-t rtype/env))) (when (access? l-exp) (check-final l-exp c-tor? static-init? c-class env)) + (when (and (eq? level 'beginner) c-tor? + (access? l-exp) (field-access? (access-name l-exp)) + (var-access-init? (field-access-access (access-name l-exp)))) + (ctor-illegal-assignment (field-access-field (access-name l-exp)) + (expr-src l-exp))) (make-type/env (case op ((=) @@ -3366,6 +3371,13 @@ (define (illegal-assignment src) (raise-error '= "Assignment is only allowed in the constructor" '= src)) + ;ctor-illegal-assignment: id src -> void + (define (ctor-illegal-assignment name src) + (raise-error '= + (format "Field ~a has already been initialized and cannot be reassigned." + (id->ext-name name)) + '= src)) + (define (assignment-error op ltype rtype src) (raise-error op (format "~a requires that the right hand type be equivalent to or a subtype of ~a: given ~a"