Procházet zdrojové kódy

[typer] infer `cf_final` if we type against a structure

Simon Krajewski před 7 roky
rodič
revize
3a76be2d03
1 změnil soubory, kde provedl 3 přidání a 0 odebrání
  1. 3 0
      src/typing/typer.ml

+ 3 - 0
src/typing/typer.ml

@@ -1652,11 +1652,13 @@ and type_object_decl ctx fl with_type p =
 		let fl = List.map (fun ((n,pn,qs),e) ->
 			let is_valid = Lexer.is_valid_identifier n in
 			if PMap.mem n !fields then error ("Duplicate field in object declaration : " ^ n) p;
+			let is_final = ref false in
 			let e = try
 				let t = match !dynamic_parameter with
 					| Some t -> t
 					| None ->
 						let cf = PMap.find n field_map in
+						if cf.cf_final then is_final := true;
 						if ctx.in_display && DisplayPosition.encloses_display_position pn then DisplayEmitter.display_field ctx Unknown CFSMember cf pn;
 						cf.cf_type
 				in
@@ -1671,6 +1673,7 @@ and type_object_decl ctx fl with_type p =
 			if is_valid then begin
 				if starts_with n '$' then error "Field names starting with a dollar are not allowed" p;
 				let cf = mk_field n e.etype (punion pn e.epos) pn in
+				if !is_final then cf.cf_final <- true;
 				fields := PMap.add n cf !fields;
 			end;
 			((n,pn,qs),e)