Skip to content

Commit

Permalink
Inline real type resolution method
Browse files Browse the repository at this point in the history
It not so big and this unifies handling of types and enums
  • Loading branch information
Mingun committed Sep 26, 2024
1 parent ae9ddae commit 6efa01a
Showing 1 changed file with 20 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,26 @@ class ResolveTypes(specs: ClassSpecs, topClass: ClassSpec, opaqueTypes: Boolean)
private def resolveUserType(curClass: ClassSpec, dataType: DataType, path: List[String]): Iterable[CompilationProblem] = {
dataType match {
case ut: UserType =>
val (resClassSpec, problems) = resolveUserType(curClass, ut.name, path ++ List("type"))
ut.classSpec = resClassSpec
problems
try {
val resolver = new ClassTypeProvider(specs, curClass)
val ty = resolver.resolveTypePath(curClass, ut.name)
Log.typeResolve.info(() => s" => ${ty.nameAsStr}")
ut.classSpec = Some(ty)
None
} catch {
case _: TypeNotFoundError =>
// Type definition not found
if (opaqueTypes) {
// Generate special "opaque placeholder" ClassSpec
Log.typeResolve.info(() => " => ??? (generating opaque type)")
ut.classSpec = Some(ClassSpec.opaquePlaceholder(ut.name))
None
} else {
// Opaque types are disabled => that is an error
Log.typeResolve.info(() => " => ??? (opaque type are disabled => error)")
Some(TypeNotFoundErr(ut.name, curClass, path :+ "type"))
}
}
case et: EnumType =>
et.name match {
case typePath :+ name =>
Expand Down Expand Up @@ -84,25 +101,4 @@ class ResolveTypes(specs: ClassSpecs, topClass: ClassSpec, opaqueTypes: Boolean)
None
}
}

private def resolveUserType(curClass: ClassSpec, typeName: List[String], path: List[String]): (Option[ClassSpec], Option[CompilationProblem]) = {
try {
val resolver = new ClassTypeProvider(specs, curClass)
val ty = resolver.resolveTypePath(curClass, typeName)
Log.typeResolve.info(() => s" => ${ty.nameAsStr}")
(Some(ty), None)
} catch {
case _: TypeNotFoundError =>
// Type definition not found
if (opaqueTypes) {
// Generate special "opaque placeholder" ClassSpec
Log.typeResolve.info(() => " => ??? (generating opaque type)")
(Some(ClassSpec.opaquePlaceholder(typeName)), None)
} else {
// Opaque types are disabled => that is an error
Log.typeResolve.info(() => " => ??? (opaque type are disabled => error)")
(None, Some(TypeNotFoundErr(typeName, curClass, path)))
}
}
}
}

0 comments on commit 6efa01a

Please sign in to comment.