# Problem when my function return a Tuple

**URL:** <https://forum.crystal-lang.org/t/problem-when-my-function-return-a-tuple/6851>\
**Category:** Help & Support\
**Created:** [May 18, 2024, 8:21am UTC](https://forum.crystal-lang.org/t/problem-when-my-function-return-a-tuple/6851 "2024-05-18T08:21:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fulgurance](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/fulgurance/32/1463_2.png) [@Fulgurance](https://forum.crystal-lang.org/u/Fulgurance)\
**Post date:** [May 18, 2024, 8:21am UTC](https://forum.crystal-lang.org/t/problem-when-my-function-return-a-tuple/6851/1 "2024-05-18T08:21:23Z")

</div>

Hi everyone, I am facing recently a problem after I updated my code on my project.  
When I call this function, at runtime crystal complain about that function can return a **Tuple(UInt128, UInt128, UInt128, UInt128)** or **NIL**.

How that is possible ?

```auto
def install : Tuple(UInt128, UInt128, UInt128, UInt128)
            Ism.notifyOfInstall(@information)

            filesList = Dir.glob(["#{builtSoftwareDirectoryPath(false)}/**/*"], match: :dot_files)
            installedFiles = Array(String).new

            directoryNumber = UInt128.new(0)
            symlinkNumber = UInt128.new(0)
            fileNumber = UInt128.new(0)
            totalSize = UInt128.new(0)

            filesList.each do |entry|

                finalDestination = "/#{entry.sub(builtSoftwareDirectoryPath(false),"")}"

                if File.directory?(entry)
                    if !Dir.exists?(finalDestination)
                        directoryNumber += 1

                        makeDirectory(finalDestination)
                        installedFiles << "/#{finalDestination.sub(Ism.settings.rootPath,"")}".squeeze("/")
                    end
                else
                    if File.symlink?(entry)
                        symlinkNumber += 1
                    else
                        fileNumber += 1
                        totalSize += File.size(entry)
                    end

                    moveFile(entry,finalDestination)
                    installedFiles << "/#{finalDestination.sub(Ism.settings.rootPath,"")}".squeeze("/")
                end

            end

            Ism.addInstalledSoftware(@information, installedFiles)
            return directoryNumber, symlinkNumber, fileNumber, totalSize
        end

```

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [May 18, 2024, 1:23pm UTC](https://forum.crystal-lang.org/t/problem-when-my-function-return-a-tuple/6851/2 "2024-05-18T13:23:08Z")

</div>

Can you share the actual error? I’m unable to reproduce this by just commenting out stuff that I don’t have defined, so are you sure you’re not re-defining this method or something somewhere else that is conflicting with it?

---

<div class="post-metadata">

**Author:** ![Fulgurance](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/fulgurance/32/1463_2.png) [@Fulgurance](https://forum.crystal-lang.org/u/Fulgurance)\
**Post date:** [May 18, 2024, 2:20pm UTC](https://forum.crystal-lang.org/t/problem-when-my-function-return-a-tuple/6851/3 "2024-05-18T14:20:35Z")

</div>

Yes my bad, sorry I wrote that issue quickly before I left home.

So that is the error I have:

```auto
Error: undefined method '[]' for Nil (compile-time type is (Tuple(UInt128, UInt128, UInt128, UInt128) | Nil))

```

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [May 18, 2024, 2:34pm UTC](https://forum.crystal-lang.org/t/problem-when-my-function-return-a-tuple/6851/4 "2024-05-18T14:34:45Z")

</div>

And how are you using this method? Is the code like:

```auto
install_counts = install

pp install_counts[0]

```

or?

---

<div class="post-metadata">

**Author:** ![Fulgurance](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/fulgurance/32/1463_2.png) [@Fulgurance](https://forum.crystal-lang.org/u/Fulgurance)\
**Post date:** [May 18, 2024, 3:04pm UTC](https://forum.crystal-lang.org/t/problem-when-my-function-return-a-tuple/6851/5 "2024-05-18T15:04:18Z")

</div>

This is how it’s called:

```auto
begin
                            target.download
                            target.check
                            target.extract
                            target.patch
                            target.prepare
                            target.configure
                            target.build
                            target.prepareInstallation

                            directoryNumber, symlinkNumber, fileNumber, totalSize = target.install

                            Ism.recordInstallationDetails(directoryNumber, symlinkNumber, fileNumber, totalSize)

                            target.recordNeededKernelFeatures
                            target.clean
                        rescue
                            if File.exists?(target.information.installedFilePath)
                                Ism.removeInstalledSoftware(target.information)
                            end

                            Ism.exitProgram
                        end

```

---

<div class="post-metadata">

**Author:** ![Fulgurance](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/fulgurance/32/1463_2.png) [@Fulgurance](https://forum.crystal-lang.org/u/Fulgurance)\
**Post date:** [May 18, 2024, 4:19pm UTC](https://forum.crystal-lang.org/t/problem-when-my-function-return-a-tuple/6851/6 "2024-05-18T16:19:41Z")

</div>

Sorry I find the reason I think.

It’s because there is a case when my script will call another class it inherit from that class it define the install function, but was returning nothing. I forgot to update it

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [May 18, 2024, 4:54pm UTC](https://forum.crystal-lang.org/t/problem-when-my-function-return-a-tuple/6851/7 "2024-05-18T16:54:39Z")

</div>

> [@Blacksmoke16](#):
>
> are you sure you’re not re-defining this method or something somewhere else that is conflicting with it?

Called it 😛

---

<div class="post-metadata">

**Author:** ![Fulgurance](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/fulgurance/32/1463_2.png) [@Fulgurance](https://forum.crystal-lang.org/u/Fulgurance)\
**Post date:** [May 20, 2024, 2:08pm UTC](https://forum.crystal-lang.org/t/problem-when-my-function-return-a-tuple/6851/8 "2024-05-20T14:08:34Z")

</div>

Ah ah sorry, I just realize I missed that advice from you 🤣

Well putted, I deserve it 🤭

Thanks for you help again anyway !

---

<div class="post-metadata">

**Author:** ![Fulgurance](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/fulgurance/32/1463_2.png) [@Fulgurance](https://forum.crystal-lang.org/u/Fulgurance)\
**Post date:** [May 20, 2024, 2:10pm UTC](https://forum.crystal-lang.org/t/problem-when-my-function-return-a-tuple/6851/9 "2024-05-20T14:10:44Z")

</div>

I will be in holidays soon. I plan to do an official video in english about my project, I will have time. Because the project actually start to become very functional now, and I need to show it more now (I need beta tester as well xD)
