@@ -1188,11 +1188,17 @@ and tc_maybe_toplevel_term env (e:term) : term (* type-checked
11881188 in
11891189 let rdc : DsEnv. record_or_dc = rdc in //for type-based disambiguation of rdc projectors below
11901190 let open FStarC.Pprint in
1191- if Some ? ( Env. expected_typ env ) && not rdc . is_record then
1192- raise_error top Errors. Error_CannotResolveRecord [
1193- text " Expected an expression of type" ^ /^ pp ( fst ( Some ?. v ( Env. expected_typ env )));
1194- text " Type" ^ /^ pp rdc . typename ^ /^ text " is not a record type." ;
1195- ];
1191+ ( if Some ? ( Env. expected_typ env ) && not rdc . is_record then
1192+ let rdc_field_names = List. map ( fun ( i , _ ) -> Ident. string_of_id i ) rdc . fields in
1193+ let bad_field = List. tryFind ( fun i -> not ( List. existsb ( fun f -> f = Ident. string_of_id ( Ident. ident_of_lid i )) rdc_field_names )) uc . uc_fields in
1194+ match bad_field with
1195+ | Some f ->
1196+ raise_error top Errors. Error_CannotResolveRecord [
1197+ text " Expected an expression of type" ^ /^ pp ( fst ( Some ?. v ( Env. expected_typ env )));
1198+ text " Type" ^ /^ pp rdc . typename ^ /^ text " is not declared as a record type;" ^ /^
1199+ text " field" ^ /^ pp f ^ /^ text " is not valid for this type." ;
1200+ ]
1201+ | None -> ());
11961202 let constructor = S. fv_to_tm constructor in
11971203 let mk_field_projector i x =
11981204 let projname = mk_field_projector_name_from_ident constrname i in
@@ -3274,11 +3280,18 @@ and tc_pat env (pat_t:typ) (p0:pat) :
32743280 let rdc , _ , constructor_fv = TcUtil. find_record_or_dc_from_head_fv env ( TcUtil. head_fv_of_typ env t ) uc p . p in
32753281 let f_sub_pats = List. zip uc . uc_fields sub_pats in
32763282 let open FStarC.Pprint in
3277- if not rdc . is_record then
3278- raise_error p Errors. Error_CannotResolveRecord [
3279- text " Expected a pattern of type" ^ /^ pp t ;
3280- text " Type" ^ /^ pp rdc . typename ^ /^ text " is not a record type." ;
3281- ];
3283+ if not rdc . is_record then begin
3284+ let rdc_field_names = List. map ( fun ( i , _ ) -> Ident. string_of_id i ) rdc . fields in
3285+ let bad_field = List. tryFind ( fun i -> not ( List. existsb ( fun f -> f = Ident. string_of_id ( Ident. ident_of_lid i )) rdc_field_names )) uc . uc_fields in
3286+ match bad_field with
3287+ | Some f ->
3288+ raise_error p Errors. Error_CannotResolveRecord [
3289+ text " Expected a pattern of type" ^ /^ pp t ;
3290+ text " Type" ^ /^ pp rdc . typename ^ /^ text " is not declared as a record type;" ^ /^
3291+ text " field" ^ /^ pp f ^ /^ text " is not valid for this type." ;
3292+ ]
3293+ | None -> ()
3294+ end ;
32823295 let sub_pats =
32833296 TcUtil. make_record_fields_in_order env uc ( Some ( Inl t )) rdc f_sub_pats
32843297 ( fun _ ->
0 commit comments