@@ -420,46 +420,47 @@ Type TypeChecker::getUnsafeMutablePointerType(SourceLoc loc, Type pointeeType) {
420
420
return getPointerType (*this , loc, pointeeType, PTK_UnsafeMutablePointer);
421
421
}
422
422
423
- static Type getStdlibType (TypeChecker &TC, Type &cached, DeclContext *dc,
424
- StringRef name) {
425
- if (cached.isNull ()) {
426
- ModuleDecl *stdlib = TC.Context .getStdlibModule ();
427
- LookupTypeResult lookup = TC.lookupMemberType (dc, ModuleType::get (stdlib),
428
- TC.Context .getIdentifier (
429
- name));
430
- if (lookup)
431
- cached = lookup.back ().MemberType ;
432
- }
433
- return cached;
434
- }
435
-
436
423
Type TypeChecker::getStringType (DeclContext *dc) {
437
- return ::getStdlibType (*this , StringType, dc, " String" );
424
+ if (auto typeDecl = Context.getStringDecl ())
425
+ return typeDecl->getDeclaredInterfaceType ();
426
+
427
+ return Type ();
438
428
}
429
+
439
430
Type TypeChecker::getSubstringType (DeclContext *dc) {
440
- return ::getStdlibType (*this , SubstringType, dc, " Substring" );
431
+ if (auto typeDecl = Context.getSubstringDecl ())
432
+ return typeDecl->getDeclaredInterfaceType ();
433
+
434
+ return Type ();
441
435
}
436
+
442
437
Type TypeChecker::getIntType (DeclContext *dc) {
443
- return ::getStdlibType (*this , IntType, dc, " Int" );
438
+ if (auto typeDecl = Context.getIntDecl ())
439
+ return typeDecl->getDeclaredInterfaceType ();
440
+
441
+ return Type ();
444
442
}
443
+
445
444
Type TypeChecker::getInt8Type (DeclContext *dc) {
446
- return ::getStdlibType (*this , Int8Type, dc, " Int8" );
445
+ if (auto typeDecl = Context.getInt8Decl ())
446
+ return typeDecl->getDeclaredInterfaceType ();
447
+
448
+ return Type ();
447
449
}
450
+
448
451
Type TypeChecker::getUInt8Type (DeclContext *dc) {
449
- return ::getStdlibType (*this , UInt8Type, dc, " UInt8" );
452
+ if (auto typeDecl = Context.getUInt8Decl ())
453
+ return typeDecl->getDeclaredInterfaceType ();
454
+
455
+ return Type ();
450
456
}
451
457
452
458
// / Find the standard type of exceptions.
453
459
// /
454
460
// / We call this the "exception type" to try to avoid confusion with
455
461
// / the AST's ErrorType node.
456
462
Type TypeChecker::getExceptionType (DeclContext *dc, SourceLoc loc) {
457
- if (NominalTypeDecl *decl = Context.getErrorDecl ())
458
- return decl->getDeclaredType ();
459
-
460
- // Not really sugar, but the actual diagnostic text is fine.
461
- diagnose (loc, diag::sugar_type_not_found, 4 );
462
- return Type ();
463
+ return Context.getErrorDecl ()->getDeclaredType ();
463
464
}
464
465
465
466
Type
0 commit comments