@@ -339,12 +339,40 @@ def findModels (e : Expr) (es : Option Expr) : TermElabM (Expr × Expr) := do
339339 return (srcI, tgtI)
340340 | _ =>
341341 match_expr etype with
342- | OpenPartialHomeomorph X Y _ _ =>
343- trace[Elab.DiffGeo.MDiff] m! "found a partial homeomorphism from { X} to { Y} "
344- return (X, Y)
345- | PartialEquiv X Y =>
346- trace[Elab.DiffGeo.MDiff] m! "found a partial equivalence from { X} to { Y} "
347- return (X, Y)
342+ | OpenPartialHomeomorph src tgt _ _ =>
343+ trace[Elab.DiffGeo.MDiff] m! "found a partial homeomorphism from { src} to { tgt} "
344+ if tgt.hasLooseBVars then
345+ -- TODO: try `T%` here, and if it works, add an interactive suggestion to use it
346+ throwError "Term {e} is a dependent function, of type {etype}\n Hint: you can use the `T%` \
347+ elaborator to convert a dependent function to a non-dependent one"
348+ let srcI ← findModel src
349+ if let some es := es then
350+ let estype ← inferType es
351+ /- Note: we use `isDefEq` here since persistent metavariable assignments in `src` and
352+ `estype` are acceptable.
353+ TODO: consider attempting to coerce `es` to a `Set`. -/
354+ if !(← isDefEq estype <|← mkAppM ``Set #[src]) then
355+ throwError "The domain {src} of {e} is not definitionally equal to the carrier type of \
356+ the set {es} : {estype}"
357+ let tgtI ← findModel tgt (src, srcI)
358+ return (srcI, tgtI)
359+ | PartialEquiv src tgt =>
360+ trace[Elab.DiffGeo.MDiff] m! "found a partial equivalence from { src} to { tgt} "
361+ if tgt.hasLooseBVars then
362+ -- TODO: try `T%` here, and if it works, add an interactive suggestion to use it
363+ throwError "Term {e} is a dependent function, of type {etype}\n Hint: you can use the `T%` \
364+ elaborator to convert a dependent function to a non-dependent one"
365+ let srcI ← findModel src
366+ if let some es := es then
367+ let estype ← inferType es
368+ /- Note: we use `isDefEq` here since persistent metavariable assignments in `src` and
369+ `estype` are acceptable.
370+ TODO: consider attempting to coerce `es` to a `Set`. -/
371+ if !(← isDefEq estype <|← mkAppM ``Set #[src]) then
372+ throwError "The domain {src} of {e} is not definitionally equal to the carrier type of \
373+ the set {es} : {estype}"
374+ let tgtI ← findModel tgt (src, srcI)
375+ return (srcI, tgtI)
348376 | _ => throwError "Expected{indentD e}\n of type{indentD etype}\n to be a function"
349377
350378end Elab
0 commit comments