Jira (PUP-7735) Regexp class parameter being understood as a String

2 views
Skip to first unread message

Christopher Wood (JIRA)

unread,
Jun 27, 2017, 12:29:02 PM6/27/17
to puppe...@googlegroups.com
Christopher Wood created an issue
 
Puppet / Bug PUP-7735
Regexp class parameter being understood as a String
Issue Type: Bug Bug
Affects Versions: PUP 4.10.2
Assignee: Unassigned
Components: Language, Type System
Created: 2017/06/27 9:28 AM
Environment:

$ puppet --version
4.10.2

$ uname -a
Linux cwl 4.9.0-3-amd64 #1 SMP Debian 4.9.30-2+deb9u1 (2017-06-18) x86_64 GNU/Linux

(Probably a bit different for other people in the #puppet discussion.)

Priority: Normal Normal
Reporter: Christopher Wood

When we pass a Regexp to a class, the class understands it as a String. To wit:

{{
class what (
Regexp[/^.$/] $param,
)

{ notice('yes') }

class

{ 'what': param => /^.$/, }

$ puppet apply /tmp/z.pp
Error: Evaluation Error: Error while evaluating a Resource Statement, Class[Classname]: parameter 'param' expects a Regexp value, got String at /tmp/z.pp:7:1 on node cwl.hostopia.com
}}

https://pastebin.com/bHJ1vqub

{{
$regexp = /^.$/
notice(type($regexp))

class foo($bar)

{ notice(type($bar)) }

class

{ 'foo': bar => $regexp }

Notice: Scope(Class[main]): Regexp[/^.$/]
Notice: Scope(Class[Foo]): String
}}

https://gist.github.com/richardc/1380cda39d7bebca19ddc9dc06fb1a16

Functions seem better though.

{{
<Volcane> function x(Regexp $thing)

{ notice(type($thing)) }

happily works
}}

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe)
Atlassian logo

Christopher Wood (JIRA)

unread,
Jun 27, 2017, 12:31:03 PM6/27/17
to puppe...@googlegroups.com
Christopher Wood updated an issue
Change By: Christopher Wood
When we pass a Regexp to a class, the class understands it as a String. To wit:

{{

class what (
  Regexp[/^.$/] $param,
) {
  notice('yes')
}
 
class { 'what':
  param => /^.$/,
}

$ puppet apply /tmp/z.pp 
Error: Evaluation Error: Error while evaluating a Resource Statement, Class[Classname]: parameter 'param' expects a Regexp value, got String at /tmp/z.pp:7:1 on node cwl.hostopia.com

}}


https://pastebin.com/bHJ1vqub


{{
$regexp = /^.$/
notice(type($regexp))

class foo($bar) {
  notice(type($bar))
}

class { 'foo': bar => $regexp }

Notice: Scope(Class[main]): Regexp[/^.$/]
Notice: Scope(Class[Foo]): String

}}


https://gist.github.com/richardc/1380cda39d7bebca19ddc9dc06fb1a16

Functions seem better though.

{
{
quote} <Volcane> function x(Regexp $thing) { notice(type($thing)) } happily works
{quote } }

Christopher Wood (JIRA)

unread,
Jun 27, 2017, 12:32:03 PM6/27/17
to puppe...@googlegroups.com

Christopher Wood (JIRA)

unread,
Jun 27, 2017, 12:33:03 PM6/27/17
to puppe...@googlegroups.com
{{ <Volcane> function x(Regexp $thing) { notice(type($thing)) } happily works }}

Henrik Lindberg (JIRA)

unread,
Jun 28, 2017, 3:40:02 AM6/28/17
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
When we pass a Regexp to a class, the class understands it as a String. To wit:
{code:puppet}
{{class what (
  Regexp[/^.$/] $param,
) {
  notice('yes')
}
 
class { 'what':
  param => /^.$/,
}
{code}
{code}
$ puppet apply /tmp/z.pp 
Error: Evaluation Error: Error while evaluating a Resource Statement, Class[Classname]: parameter 'param' expects a Regexp value, got String at /tmp/z.pp:7:1 on node cwl.hostopia.com}}


{{$regexp = /^.$/
notice(type($regexp))

class foo($bar) {
  notice(type($bar))
}

class { 'foo': bar => $regexp }

Notice: Scope(Class[main]): Regexp[/^.$/]
Notice: Scope(Class[Foo]): String}}
{code}

https://gist.github.com/richardc/1380cda39d7bebca19ddc9dc06fb1a16

Functions seem better though.

<Volcane> function x(Regexp $thing) { notice(type($thing)) } happily works

Henrik Lindberg (JIRA)

unread,
Jun 28, 2017, 3:59:03 AM6/28/17
to puppe...@googlegroups.com
Henrik Lindberg commented on Bug PUP-7735
 
Re: Regexp class parameter being understood as a String

It is a known problem that Puppet resources (classes, native resource types, and user defined types) cannot use rich data types as they cannot be represented in the resulting catalog. The so called 3.x catalog API requires that we transform such values to String (or we would break backwards compatibility). We are on a path to remove this restriction and have come quite far on solving this issue. There is an experimental feature flag --rich_data that will encode rich data in catalogs and reports. It must be turned on both on agents and on the master.

When using this feature there may be issues with logic that expected the behavior that "regexps are turned into strings".

henrik$ puppet apply pup7735.pp
Error: Evaluation Error: Error while evaluating a Resource Statement, Class[What]: parameter 'param' expects a Regexp value, got String at /Users/henrik/git/puppet/pup7735.pp:5:1 on node henrik2

henrik$ puppet apply pup7735.pp --rich_data
Notice: Scope(Class[What]): yes
Notice: Compiled catalog for henrik2 in environment production in 0.03 seconds
Notice: Applied catalog in 0.02 seconds

Henrik Lindberg (JIRA)

unread,
Jun 28, 2017, 4:55:02 AM6/28/17
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
Sub-team: Language
Team: Agent
Component/s: Compiler

Henrik Lindberg (JIRA)

unread,
Jun 28, 2017, 4:55:03 AM6/28/17
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
Environment: $ puppet --version
4.10.2


$ uname -a
Linux cwl 4.9.0-3-amd64 #1 SMP Debian 4.9.30-2+deb9u1 (2017-06-18) x86_64 GNU/Linux

(Probably a bit different for other people in the #puppet discussion.)

Henrik Lindberg (JIRA)

unread,
Jun 28, 2017, 4:56:02 AM6/28/17
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
{code:puppet}
# From
<Volcane>  
 function x(Regexp $thing) { notice(type($thing)) }
{code}
 happily works
.

Henrik Lindberg (JIRA)

unread,
May 9, 2019, 9:08:04 AM5/9/19
to puppe...@googlegroups.com
 
Re: Regexp class parameter being understood as a String

Cannot replicate this with latest Puppet 5. Closing this ticket as 4.x is EOL.

This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages