Skip to content

Commit

Permalink
Revert r18204: Handle T* in an expression context, so long as '*' is …
Browse files Browse the repository at this point in the history
…postfix.

Swift SVN r18253
  • Loading branch information
DougGregor committed May 17, 2014
1 parent be3dbf2 commit 6606b05
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 51 deletions.
11 changes: 0 additions & 11 deletions lib/Sema/CSGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,17 +353,6 @@ namespace {
}

Type visitUnresolvedDeclRefExpr(UnresolvedDeclRefExpr *expr) {
// We might have an operator that couldn't be resolved earlier.
if (expr->getRefKind() != DeclRefKind::Ordinary) {
auto &tc = CS.getTypeChecker();
tc.diagnose(expr->getLoc(), diag::use_nonmatching_operator,
expr->getName(),
expr->getRefKind() == DeclRefKind::BinaryOperator ? 0 :
expr->getRefKind() == DeclRefKind::PrefixOperator ? 1 : 2);

return Type();
}

// This is an error case, where we're trying to use type inference
// to help us determine which declaration the user meant to refer to.
// FIXME: Do we need to note that we're doing some kind of recovery?
Expand Down
35 changes: 1 addition & 34 deletions lib/Sema/TypeCheckConstraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,6 @@ static Expr *BindName(UnresolvedDeclRefExpr *UDRE, DeclContext *Context,
if (AllDeclRefs) {
// Diagnose uses of operators that found no matching candidates.
if (ResultValues.empty()) {
// If this is a postfix '*', it might be part of type sugar for
// an unsafe pointer, so delay resolution of this declaration
// reference.
if (UDRE->getRefKind() == DeclRefKind::PostfixOperator &&
UDRE->getName().str() == "*")
return UDRE;

assert(UDRE->getRefKind() != DeclRefKind::Ordinary);
TC.diagnose(Loc, diag::use_nonmatching_operator, Name,
UDRE->getRefKind() == DeclRefKind::BinaryOperator ? 0 :
Expand Down Expand Up @@ -539,16 +532,6 @@ bool PreCheckExpression::walkToClosureExprPre(ClosureExpr *closure) {
return true;
}

static bool isAsteriskRef(Expr *E) {
if (auto UDRE = dyn_cast<UnresolvedDeclRefExpr>(E))
return UDRE->getName().str() == "*";
if (auto DRE = dyn_cast<DeclRefExpr>(E))
return DRE->getDecl()->getName().str() == "*";
if (auto ODRE = dyn_cast<OverloadedDeclRefExpr>(E))
return ODRE->getDecls()[0]->getName().str() == "*";
return false;
}

/// Simplify expressions which are type sugar productions that got parsed
/// as expressions due to the parser not knowing which identifiers are
/// type names.
Expand Down Expand Up @@ -596,23 +579,7 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
new (TC.Context) OptionalTypeRepr(InnerTypeRepr, QuestionLoc);
return new (TC.Context) TypeExpr(TypeLoc(NewTypeRepr, Type()));
}

// Fold T* into an unsafe pointer type with T is a TypeExpr, postfix
// case.
if (auto *PUE = dyn_cast<PostfixUnaryExpr>(E)) {
auto *TyExpr = dyn_cast<TypeExpr>(PUE->getArg());
if (!TyExpr) return nullptr;

if (!isAsteriskRef(PUE->getFn()))
return nullptr;

auto *InnerTypeRepr = TyExpr->getTypeRepr();
auto *NewTypeRepr
= new (TC.Context) UnsafePointerTypeRepr(InnerTypeRepr,
PUE->getFn()->getLoc());
return new (TC.Context) TypeExpr(TypeLoc(NewTypeRepr, Type()));
}


// Fold (T) into a type T with parens around it.
if (auto *PE = dyn_cast<ParenExpr>(E)) {
auto *TyExpr = dyn_cast<TypeExpr>(PE->getSubExpr());
Expand Down
6 changes: 0 additions & 6 deletions test/type/types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,4 @@ func test_optional_construct<T>() {
var c = (Int?)() // Parenthesized name.
}

// postfix * as sugar in expressions,
func test_unsafe_pointer_construct_postfix<T>(t: T) {
var a = T* ()
var b = (T*)()
}

// FIXME: * is infix is a delight

0 comments on commit 6606b05

Please sign in to comment.