Ticket #1512 (new bug)

Opened 12 years ago

Last modified 11 years ago

NQP-rx generates bad access code for non-twigiled attribute

Reported by: Austin_Hastings Owned by: pmichaud
Priority: normal Milestone:
Component: nqp Version: 2.1.0
Severity: medium Keywords:
Cc: Language:
Patch status: Platform:

Description

This code, with twigil:

austin@andLinux:~/kakapo$ cat test.nqp
method foo() {
	has @!attr;

	for my @a {
		say(@!attr);
	}
}

Generates this pir:

.annotate "line", 5
    find_lex $P24, "self"
    getattribute $P25, $P24, "@!attr"
    unless_null $P25, vivify_14
    new $P25, "ResizablePMCArray"
  vivify_14:

Whereas this code, sans twigil:

austin@andLinux:~/kakapo$ cat test.nqp
method foo() {
	has @attr;

	for my @a {
		say(@attr);
	}
}

Generates this output:

.annotate "line", 5
    getattribute $P24, self, "@attr"
    $P25 = "say"($P24)
.annotate "line", 4

Because the sub is a nested block, it has no method declaration and so must do a find-lex lookup to get 'self'. This is not happening. Since the grammar does not support '.' as a twigil, which I think it should, I'm not sure if an attribute with no twigil is or isn't valid. If it's not valid, then the has @attr declaration should throw an error. If it's valid, then the access code should work.

Change History

Changed 12 years ago by Austin_Hastings

Also, '?' as a twigil exhibits the same bad behavior. ('*' goes a totally different route, and appears to work)

Changed 11 years ago by jkeenan

  • owner set to pmichaud
  • component changed from none to nqp

Changed 11 years ago by pmichaud

I think I'm going to decide that attribute declarations require the ! twigil, at least for nqp-rx. So, the real problem here becomes that nqp-rx is allowing attribute declarations without the ! twigil, and fixing that likely requires a deprecation cycle.

Pm

Note: See TracTickets for help on using tickets.