|
34 | 34 | #include "absl/types/span.h" |
35 | 35 | #include "base/ast_internal/ast_impl.h" |
36 | 36 | #include "base/ast_internal/expr.h" |
| 37 | +#include "checker/checker_options.h" |
37 | 38 | #include "checker/internal/namespace_generator.h" |
38 | 39 | #include "checker/internal/type_check_env.h" |
39 | 40 | #include "checker/internal/type_inference_context.h" |
@@ -613,7 +614,7 @@ void ResolveVisitor::PostVisitMap(const Expr& expr, const MapExpr& map) { |
613 | 614 | if (value_type.IsOptional()) { |
614 | 615 | value_type = value_type.GetOptional().GetParameter(); |
615 | 616 | } else { |
616 | | - ReportTypeMismatch(entry.id(), OptionalType(arena_, value_type), |
| 617 | + ReportTypeMismatch(entry.value().id(), OptionalType(arena_, value_type), |
617 | 618 | value_type); |
618 | 619 | continue; |
619 | 620 | } |
@@ -829,7 +830,7 @@ void ResolveVisitor::PostVisitComprehensionSubexpression( |
829 | 830 | break; |
830 | 831 | default: |
831 | 832 | issues_->push_back(TypeCheckIssue::CreateError( |
832 | | - ComputeSourceLocation(*ast_, expr.id()), |
| 833 | + ComputeSourceLocation(*ast_, comprehension.iter_range().id()), |
833 | 834 | absl::StrCat( |
834 | 835 | "expression of type '", |
835 | 836 | inference_context_->FinalizeType(range_type).DebugString(), |
@@ -898,12 +899,12 @@ void ResolveVisitor::ResolveFunctionOverloads(const Expr& expr, |
898 | 899 | issues_->push_back(TypeCheckIssue::CreateError( |
899 | 900 | ComputeSourceLocation(*ast_, expr.id()), |
900 | 901 | absl::StrCat("found no matching overload for '", decl.name(), |
901 | | - "' applied to (", |
| 902 | + "' applied to '(", |
902 | 903 | absl::StrJoin(arg_types, ", ", |
903 | 904 | [](std::string* out, const Type& type) { |
904 | 905 | out->append(type.DebugString()); |
905 | 906 | }), |
906 | | - ")"))); |
| 907 | + ")'"))); |
907 | 908 | return; |
908 | 909 | } |
909 | 910 |
|
@@ -1135,12 +1136,14 @@ class ResolveRewriter : public AstRewriterBase { |
1135 | 1136 | public: |
1136 | 1137 | explicit ResolveRewriter(const ResolveVisitor& visitor, |
1137 | 1138 | const TypeInferenceContext& inference_context, |
| 1139 | + const CheckerOptions& options, |
1138 | 1140 | AstImpl::ReferenceMap& references, |
1139 | 1141 | AstImpl::TypeMap& types) |
1140 | 1142 | : visitor_(visitor), |
1141 | 1143 | inference_context_(inference_context), |
1142 | 1144 | reference_map_(references), |
1143 | | - type_map_(types) {} |
| 1145 | + type_map_(types), |
| 1146 | + options_(options) {} |
1144 | 1147 | bool PostVisitRewrite(Expr& expr) override { |
1145 | 1148 | bool rewritten = false; |
1146 | 1149 | if (auto iter = visitor_.attributes().find(&expr); |
@@ -1172,7 +1175,7 @@ class ResolveRewriter : public AstRewriterBase { |
1172 | 1175 | iter != visitor_.struct_types().end()) { |
1173 | 1176 | auto& ast_ref = reference_map_[expr.id()]; |
1174 | 1177 | ast_ref.set_name(iter->second); |
1175 | | - if (expr.has_struct_expr()) { |
| 1178 | + if (expr.has_struct_expr() && options_.update_struct_type_names) { |
1176 | 1179 | expr.mutable_struct_expr().set_name(iter->second); |
1177 | 1180 | } |
1178 | 1181 | rewritten = true; |
@@ -1202,6 +1205,7 @@ class ResolveRewriter : public AstRewriterBase { |
1202 | 1205 | const TypeInferenceContext& inference_context_; |
1203 | 1206 | AstImpl::ReferenceMap& reference_map_; |
1204 | 1207 | AstImpl::TypeMap& type_map_; |
| 1208 | + const CheckerOptions& options_; |
1205 | 1209 | }; |
1206 | 1210 |
|
1207 | 1211 | } // namespace |
@@ -1237,7 +1241,7 @@ absl::StatusOr<ValidationResult> TypeCheckerImpl::Check( |
1237 | 1241 | // Apply updates as needed. |
1238 | 1242 | // Happens in a second pass to simplify validating that pointers haven't |
1239 | 1243 | // been invalidated by other updates. |
1240 | | - ResolveRewriter rewriter(visitor, type_inference_context, |
| 1244 | + ResolveRewriter rewriter(visitor, type_inference_context, options_, |
1241 | 1245 | ast_impl.reference_map(), ast_impl.type_map()); |
1242 | 1246 | AstRewrite(ast_impl.root_expr(), rewriter); |
1243 | 1247 |
|
|
0 commit comments