[swift-dev] Unexpected Expr type

Halen Wooten swift at hpwooten.com
Thu Apr 6 18:02:56 CDT 2017

Hi Jordan,

Thanks for your reply. I tried the `dyn_cast<ParenExpr>(src)`, but it
gives me null. Here's what I've added:

bool TypeChecker::diagnoseSelfAssignment(const Expr *E) {


  auto src = AE->getSrc();
  auto parenSrc = dyn_cast<ParenExpr>(src);
  if (parenSrc)
    return false;



On Thu, Apr 6, 2017 at 6:49 PM, Jordan Rose <jordan_rose at apple.com> wrote:
> Hi, Halen. Welcome to the compiler. :-) What you're seeing is that we don't
> usually use C++'s normal RTTI mechanism, but instead go with a "Kind" field
> that's checked by the custom 'cast', 'dyn_cast', and 'isa' functions. (More
> information in the LLVM Programmer's Manual.) The debugger doesn't know
> about this, so it just always shows the base class to be conservative. If
> you're debugging, you can call dump() to see what kind of Expr it really is,
> and then cast the pointer down to the right type as needed. In your actual
> code, you can check `isa<ParenExpr>(src)`, or `dyn_cast<ParenExpr>(src)` if
> you then need to manipulate the ParenExpr.
> Hope that helps,
> Jordan
> On Apr 6, 2017, at 15:30, Halen Wooten via swift-dev <swift-dev at swift.org>
> wrote:
> Hi swift devs,
> I'm working on SR-4464 to learn how to contribute to Swift. I think I
> have the solution, but I'm getting unexpected results.
> I'm using the swift repl within Xcode for testing. Here's my test code.
> var name = "name"
> name = (name)
> In TypeChecker::diagnoseSelfAssignment in CSDiag.cpp, the src of the
> AssignExpr is a plain Expr *, but I would expect it to be a ParenExpr
> *. Could someone help me figure out what's happening?
> Thanks,
> Halen
> _______________________________________________
> swift-dev mailing list
> swift-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-dev

More information about the swift-dev mailing list